python学习过程中遇到的疑问

Kvm、VMware、Virtualbox、Xen、Qemu 等
jinjiachen
帖子: 2148
注册时间: 2012-12-16 15:43
系统: debian

python学习过程中遇到的疑问

#1

帖子 jinjiachen » 2014-07-09 14:18

最近下决心学习python,其间遇到一些问题有些困扰,特此来向大家学习和讨论。
我是按着这个网站来学习的:http://www.w3cschool.cc/python/python-files-io.html
学习过程中有些例子我发现在我的电脑上并不可行,举出我印象深刻的几点。
1。raw_input这个函数,我在python中运行时提示未定义,这不是内置函数吗?
2。就是关于中文编码,有好多种说法,有的是coding:utf8,有的是coding.utf-8,可惜的是,两个都不能成功,请告诉哪个才是可行的,且规范的
3。python的断句是;号吗,感觉没有也可以的样子,不会出错,如果不加;号规范吗?


------------------------------------2014-07-11更新--------------------------------------------------------
按照这个教程练习,运行时出现如下错误,关于这个类,我还在学习不是很懂,所以看不出问题,感觉没错,请大家帮我看看错哪了,谢谢
Traceback (most recent call last):
File "main.py", line 19, in <module>
emp2=employee('manni',5000)
TypeError: object() takes no parameters
------------------------------------2014-07-15------------
python里的模块,包什么的,有什么区别和标志吗?个人认为就是写有python代码的文件,可是好像在导入的时候还是要区分,能普及下吗,不太懂
附件
py.png
上次由 jinjiachen 在 2014-07-15 21:19,总共编辑 2 次。
头像
zhw2101024
帖子: 1849
注册时间: 2009-03-28 16:10
系统: Arch debian win7
联系:

Re: python学习过程中遇到的疑问

#2

帖子 zhw2101024 » 2014-07-09 17:32

1.python --version看看什么版本,如果是python3的话已经用input取代了raw_input
2.python3已经有了完整的utf8支持,你说的coding:utf8应该是python2用的。
3.python用空格或者tab来控制语法结构,断句不重要,除非把两条语句写在一行。

楼主给的链接打不开,建议检查一下参考的资料是否明确了python版本。
jinjiachen
帖子: 2148
注册时间: 2012-12-16 15:43
系统: debian

Re: python学习过程中遇到的疑问

#3

帖子 jinjiachen » 2014-07-09 19:38

zhw2101024 写了:1.python --version看看什么版本,如果是python3的话已经用input取代了raw_input
2.python3已经有了完整的utf8支持,你说的coding:utf8应该是python2用的。
3.python用空格或者tab来控制语法结构,断句不重要,除非把两条语句写在一行。

楼主给的链接打不开,建议检查一下参考的资料是否明确了python版本。
经核查是3.3,谢谢你的回答,原来那些都是过去时了 :em09
jinjiachen
帖子: 2148
注册时间: 2012-12-16 15:43
系统: debian

Re: python学习过程中遇到的疑问

#4

帖子 jinjiachen » 2014-07-13 9:18

没有人帮忙解答吗
头像
月下叹逍遥
论坛版主
帖子: 33994
注册时间: 2010-10-07 14:23
系统: Archdows10
来自: 某系某星某洲某国某省某市
联系:

Re: python学习过程中遇到的疑问

#5

帖子 月下叹逍遥 » 2014-07-13 9:58

coding=utf-8
py没有符号断句,用TAB键

来自我的 MI 2S 上的 Tapatalk
浮生七十今三十,从此凄惶未可知
头像
langyxxl
帖子: 443
注册时间: 2012-01-17 22:17

Re: python学习过程中遇到的疑问

#6

帖子 langyxxl » 2014-07-13 11:58

买本简单的python书,看一个礼拜,应该很有用
jinjiachen
帖子: 2148
注册时间: 2012-12-16 15:43
系统: debian

Re: python学习过程中遇到的疑问

#7

帖子 jinjiachen » 2014-07-13 12:00

langyxxl 写了:买本简单的python书,看一个礼拜,应该很有用
我正在看简明教程
jinjiachen
帖子: 2148
注册时间: 2012-12-16 15:43
系统: debian

Re: python学习过程中遇到的疑问

#8

帖子 jinjiachen » 2014-07-13 20:12

那个例子不能成功运行的原因 我找到了,是那个_init_出的问题,我只打了一个下划线,要打两个,我一开始认为只是定义一个函数,名字是随便取的,没想到是固定的,不知道为什么
jinjiachen
帖子: 2148
注册时间: 2012-12-16 15:43
系统: debian

Re: python学习过程中遇到的疑问

#9

帖子 jinjiachen » 2014-07-17 12:54

学了python的基础教程,现在想接触下做界面,请问下大家都是选择什么来做界面的?GTK?QT?WXpython?
我想安装wxpython不过在其官网上看到的好像只有支持到python2.x 对于3好像还没有支持,是这样吗?
头像
langyxxl
帖子: 443
注册时间: 2012-01-17 22:17

Re: python学习过程中遇到的疑问

#10

帖子 langyxxl » 2014-07-17 19:29

我现在的项目组开发的是pyqt程序
jinjiachen
帖子: 2148
注册时间: 2012-12-16 15:43
系统: debian

Re: python学习过程中遇到的疑问

#11

帖子 jinjiachen » 2014-07-18 20:45

#coding=utf-8
#!/usr/bin/env python
'Hello, wxPython! program.'
import wx

class Frame(wx.Frame):
'Frame class that displays an image.'
def __init__(self, image, parent=None, id=-1,
pos=wx.DefaultPosition,
title='Hello, wxPython!'): #3图像参数
'Create a Frame instance and display image.'
#4 显示图像
temp = image.ConvertToBitmap()
size = temp.GetWidth(), temp.GetHeight()
wx.Frame.__init__(self, parent, id, title, pos, size)
self.bmp = wx.StaticBitmap(parent=self, bitmap=temp)

class App(wx.App): #5 wx.App子类
'Application class.'
def OnInit(self):
#6 图像处理
image = wx.Image('wxPython.jpg', wx.BITMAP_TYPE_JPEG)
self.frame = Frame(image)
self.frame.Show()
self.SetTopWindow(self.frame)
return True
def main(): #7
app = App()
app.MainLoop()
if __name__ == '__main__':
main()


--------------------
以上是源代码,在编译时出现错误,提示:SyntaxError: Non-ASCII character '\xe5' in file hello.py on line 5
我在网上查了下,是编码问题,加上了第一行编码,可是运行还是有错,不知道为何,请大家指教下
jinjiachen
帖子: 2148
注册时间: 2012-12-16 15:43
系统: debian

Re: python学习过程中遇到的疑问

#12

帖子 jinjiachen » 2014-07-18 20:45

#coding=utf-8
#!/usr/bin/env python
'Hello, wxPython! program.'
import wx

class Frame(wx.Frame):
'Frame class that displays an image.'
def __init__(self, image, parent=None, id=-1,
pos=wx.DefaultPosition,
title='Hello, wxPython!'): #3图像参数
'Create a Frame instance and display image.'
#4 显示图像
temp = image.ConvertToBitmap()
size = temp.GetWidth(), temp.GetHeight()
wx.Frame.__init__(self, parent, id, title, pos, size)
self.bmp = wx.StaticBitmap(parent=self, bitmap=temp)

class App(wx.App): #5 wx.App子类
'Application class.'
def OnInit(self):
#6 图像处理
image = wx.Image('wxPython.jpg', wx.BITMAP_TYPE_JPEG)
self.frame = Frame(image)
self.frame.Show()
self.SetTopWindow(self.frame)
return True
def main(): #7
app = App()
app.MainLoop()
if __name__ == '__main__':
main()


--------------------
以上是源代码,在编译时出现错误,提示:SyntaxError: Non-ASCII character '\xe5' in file hello.py on line 5
我在网上查了下,是编码问题,加上了第一行编码,可是运行还是有错,不知道为何,请大家指教下
jinjiachen
帖子: 2148
注册时间: 2012-12-16 15:43
系统: debian

Re: python学习过程中遇到的疑问

#13

帖子 jinjiachen » 2014-07-18 20:51

网上都说什么加上#coding=utf-8完成没用,还到处抄袭的,真是害人啊
jinjiachen
帖子: 2148
注册时间: 2012-12-16 15:43
系统: debian

Re: python学习过程中遇到的疑问

#14

帖子 jinjiachen » 2014-07-19 6:55

我的是2.7所以要加编码声明 不过两种方式都不对
jinjiachen
帖子: 2148
注册时间: 2012-12-16 15:43
系统: debian

Re: python学习过程中遇到的疑问

#15

帖子 jinjiachen » 2014-07-19 21:44

想安装wxpython,在源里没搜到,只好去官网下,没有deb包,我是debian的,只好编译,可是水平不够,出现如下错误:
configure: error:
The development files for GTK+ were not found. For GTK+ 2, please
ensure that pkg-config is in the path and that gtk+-2.0.pc is
installed. For GTK+ 1.2 please check that gtk-config is in the path,
and that the version is 1.2.3 or above. Also check that the
libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config
--libs' are in the LD_LIBRARY_PATH or equivalent.

Error running configure
ERROR: failed building wxWidgets
Traceback (most recent call last):
File "build-wxpython.py", line 378, in <module>
wxbuild.main(wxscript, build_options)
File "/usr/src/wxPython-src-3.0.0.0/build/tools/build-wxwidgets.py", line 364, in main
"Error running configure")
File "/usr/src/wxPython-src-3.0.0.0/build/tools/build-wxwidgets.py", line 80, in exitIfError
raise builder.BuildError(msg)
BuildError
不知道是哪里错了,有编译过的朋友吗?
回复