issue on internal import in a package

2011-02-27 Thread
Here is a simple example: [app] [module] __init__.py -- empty a.py -- import b b.py -- defined a function foo() test.py In the test.py, contains the below statement: from module import a Execute the test.py will get error: Traceback (most

Re: issue on internal import in a package

2011-02-27 Thread
On Feb 27, 8:11 pm, 人言落日是天涯,望极天涯不见家 kelvin@gmail.com wrote: Here is a simple example: [app]       [module]             __init__.py   -- empty             a.py   -- import b             b.py  -- defined a function foo()       test.py In the test.py, contains the below statement: from

Re: issue on internal import in a package

2011-02-27 Thread
On Feb 27, 8:40 pm, Ben Finney ben+pyt...@benfinney.id.au wrote: 人言落日是天涯,望极天涯不见家 kelvin@gmail.com writes: Here is a simple example: [app]       [module]             __init__.py   -- empty             a.py   -- import b             b.py  -- defined a function foo()       test.py

Re: issue on internal import in a package

2011-02-27 Thread
On Feb 27, 9:22 pm, Frank Millman fr...@chagford.com wrote: Ben Finney ben+pyt...@benfinney.id.au wrote in message news:87ei6t646h@benfinney.id.au... 人言落日是天涯,望极天涯不见家 kelvin@gmail.com writes: Here is a simple example: [app]       [module]             __init__.py   -- empty

Re: issue on internal import in a package

2011-02-27 Thread
On Feb 27, 9:38 pm, Frank Millman fr...@chagford.com wrote: 人言落日是天涯,望极天涯不见家 kelvin@gmail.com wrote in message news:fa94323b-d859-4599-b236-c78a22b3d...@t19g2000prd.googlegroups.com... On Feb 27, 9:22 pm, Frank Millman fr...@chagford.com wrote: This behavior is by design or just a bug

Re: default value for __init__ doesn't work

2010-09-11 Thread
On Sep 11, 1:14 pm, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Sat, Sep 11, 2010 at 12:38 AM, 人言落日是天涯,望极天涯不见家 kelvin@gmail.com wrote: Please look at below code snippet: class test():    def __init__(self, a, dic={}):        self.a = a        self.dic = dic        print

Re: default value for __init__ doesn't work

2010-09-11 Thread
On Sep 11, 1:55 pm, 人言落日是天涯,望极天涯不见家 kelvin@gmail.com wrote: On Sep 11, 1:14 pm, Benjamin Kaplan benjamin.kap...@case.edu wrote: On Sat, Sep 11, 2010 at 12:38 AM, 人言落日是天涯,望极天涯不见家 kelvin@gmail.com wrote: Please look at below code snippet: class test():    def __init__(self

default value for __init__ doesn't work

2010-09-10 Thread
Please look at below code snippet: class test(): def __init__(self, a, dic={}): self.a = a self.dic = dic print('__init__ params:',a, dic) def get(self): self.dic[1] = 2 self.dic[4] = 5 def foo(): print('in foo function') bar = test(1)

Floating Number format problem

2007-06-12 Thread
How could I format the float number like this: (keep 2 digit precision) 1.002 = 1 1.12 = 1.12 1.00 = 1 1.567 = 1.57 2324.012 = 2324.01 I can not find any Formatting Operations is able to meet my requirement. Any suggestion will be appreciated. --

Why can not catch the inner exception

2007-06-07 Thread
Please see the follow code, I can not catch the exception IOError raised from shutil.copyfile() , why? try: if (DEST_TYPE TYPE_FTP): fn = oname ftpc.UploadFile(f, fn) else:

Does unicode() equal to unicode(sys.getfilesystemencoding()) ?

2007-06-06 Thread
The follow statement comes from the Python 2.5 documentation -- encode( [encoding[,errors]]) Return an encoded version of the string. Default encoding is the current default string encoding. errors may be given to set a different error handling scheme. --- what's the

Re: How to print this character u'\u20ac' to DOS terminal

2007-05-30 Thread
On 5月30日, 下午1时23分, Martin v. Lowis [EMAIL PROTECTED] wrote: 人言落日是天涯,望极天涯不见家 schrieb: Who could explain the follow issue ? print u'\u0394' Δ print u'\u20ac' Traceback (most recent call last): File stdin, line 1, in module UnicodeEncodeError: 'gbk' codec can't encode character u

Re: How to print this character u'\u20ac' to DOS terminal

2007-05-30 Thread
On 5月30日, 下午9时03分, Tijs [EMAIL PROTECTED] wrote: ??? wrote: But the string contained the u'\u20ac' is get from remote host. Is there any method to decode it to the local 'mbcs'? remote_string = u'\u20ac' try: local_string = remote_string.encode('mbcs') except: # no

Re: how to print the GREEK CAPITAL LETTER delta under utf-8 encoding

2007-05-29 Thread
On 5月29日, 下午1时34分, Martin v. Lowis [EMAIL PROTECTED] wrote: 人言落日是天涯,望极天涯不见家 schrieb: I lookup the utf-8 form of delta from the link. http://www.fileformat.info/info/unicode/char/0394/index.htm and then I want to print it in the python ( I work under windows) #!/usr/bin/python #coding

Re: how to print the GREEK CAPITAL LETTER delta under utf-8 encoding

2007-05-29 Thread
On 5月29日, 下午3时05分, Martin v. Lowis [EMAIL PROTECTED] wrote: yes, it could print to the terminal(cmd.exe), but when I write these string to file. I got the follow error: File E:\Tools\filegen\filegen.py, line 212, in write self.file.write(data) UnicodeEncodeError: 'ascii' codec

How to print this character u'\u20ac' to DOS terminal

2007-05-29 Thread
Who could explain the follow issue ? print u'Δ' Δ print u'�' Traceback (most recent call last): File stdin, line 1, in module UnicodeEncodeError: 'gbk' codec can't encode character u'\x80' in position 0: il legal multibyte sequence or I just put the unicode number print u'\u0394' Δ print

Issue of redirecting the stdout to both file and screen

2007-05-28 Thread
I wanna print the log to both the screen and file, so I simulatered a 'tee' class Tee(file): def __init__(self, name, mode): file.__init__(self, name, mode) self.stdout = sys.stdout sys.stdout = self def __del__(self): sys.stdout = self.stdout

Re: Issue of redirecting the stdout to both file and screen

2007-05-28 Thread
I see. Many thanks to you! -- http://mail.python.org/mailman/listinfo/python-list

how to print the GREEK CAPITAL LETTER delta under utf-8 encoding

2007-05-28 Thread
I lookup the utf-8 form of delta from the link. http://www.fileformat.info/info/unicode/char/0394/index.htm and then I want to print it in the python ( I work under windows) #!/usr/bin/python #coding=utf-8 print \xce\x94 but the result is not the 'delta' but an unknown character. --

Re: how to refer to partial list, slice is too slow?

2007-05-11 Thread
I make a sample here for the more clearly explanation s = . - this is a large string data - ... def parser1(data) # do some parser ... # pass the remainder to next parser parser2(data[100:]) def parser2(data) # do some parser ... # pass the remainder

how to refer to partial list, slice is too slow?

2007-05-10 Thread
I'm a python newbie. It seems the slice operation will do copy. for example: a = [1,2,3,4,5,6,7,8,9,0] b = a[7:] b [8, 9, 0] a.remove(9) a [1, 2, 3, 4, 5, 6, 7, 8, 0] b [8, 9, 0] if the list have large members, the slice operations will consume many times. for instance, I have a long string

What's the life time of the variable defined in a class function?

2007-04-30 Thread
Please see the followed example: class A: def __init__(self): pass class X: def __init__(self): n = 200 if True: j = 200 m = j k = A() print m, j a = X() # ?? what about the m, n and j? is it still alive? del a

Re: What's the life time of the variable defined in a class function?

2007-04-30 Thread
On Apr 30, 5:20 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: 人言落日是天涯,望极天涯不见家 wrote: Please see the followed example: class A:     def __init__(self):         pass class X:     def __init__(self):         n = 200         if True:             j = 200         m = j         k

Re: How do I parse a string to a tuple??

2007-04-30 Thread
On Apr 30, 5:47 pm, Soren [EMAIL PROTECTED] wrote: Hi! I have a string that contains some text and newline characters. I want to parse the string so that the string just before a newline character goes in as an element in the tuple. ex: text1 \n text2 \n text3 \n text4   -- (text1, text2,

Could zipfile module process the zip data in memory?

2007-04-29 Thread
I made a C/S network program, the client receive the zip file from the server, and read the data into a variable. how could I process the zipfile directly without saving it into file. In the document of the zipfile module, I note that it mentions the file-like object? what does it mean? class

Re: Could zipfile module process the zip data in memory?

2007-04-29 Thread
On Apr 29, 7:37 pm, Daniel Nogradi [EMAIL PROTECTED] wrote: I made a C/S network program, the client receive the zip file from the server, and read the data into a variable. how could I process the zipfile directly without saving it into file. In the document of the zipfile module, I note

Re: Could zipfile module process the zip data in memory?

2007-04-29 Thread
On Apr 29, 7:37 pm, Daniel Nogradi [EMAIL PROTECTED] wrote: I made a C/S network program, the client receive the zip file from the server, and read the data into a variable. how could I process the zipfile directly without saving it into file. In the document of the zipfile module, I note

Re: Could zipfile module process the zip data in memory?

2007-04-29 Thread
On Apr 29, 8:14 pm, Daniel Nogradi [EMAIL PROTECTED] wrote: I made a C/S network program, the client receive the zip file from the server, and read the data into a variable. how could I process the zipfile directly without saving it into file. In the document of the zipfile module,

ctypes: how to make a structure pointer to point to a buffer

2007-04-23 Thread
first, I'm try the POINTER to convesion the pointer type. but failed. class STUDENT(Structure): _fields_ = [('name', c_int), ('id', c_int), ('addition',c_ubyte)] buffer = c_byte * 1024 student_p = cast(buffer, POINTER(STUDENT)) The parameter of

Re: ctypes: how to make a structure pointer to point to a buffer

2007-04-23 Thread
On Apr 23, 5:42 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: 人言落日是天涯,望极天涯不见家 wrote: first, I'm try the POINTER to convesion the pointer type. but failed. class STUDENT(Structure):     _fields_ = [('name',  c_int),                     ('id',   c_int),                     ('addition

How to generate a continuous string

2007-04-16 Thread
How to generate a continuous string, like this aaa the number of characters is dynamic. Is there a module or function implement this string ? such as: duplicate_string(char, num) -- http://mail.python.org/mailman/listinfo/python-list

Re: Shutting down windows using win32api

2007-04-11 Thread
On Apr 11, 7:49 pm, Tim Golden [EMAIL PROTECTED] wrote: On a whim, given the terseness of your post, I cut-and-pasted your subject line into Google, added python for good measure, and looked at the results. I suggest you might do the same. Granted, maybe this will raise more questions, but

Does python have the static function member like C++

2007-04-10 Thread
I define the class like this: class AAA: counter = 0 def __init__(self): pass def counter_increase(): AAA.counter += 1 print couter now :, AAA.counter But how could I call the function counter_incrrease ? Thanks ! --

Re: Does python have the static function member like C++

2007-04-10 Thread
On Apr 11, 11:19 am, 7stud [EMAIL PROTECTED] wrote: On Apr 10, 9:08 pm, 人言落日是天涯,望极天涯不见家 [EMAIL PROTECTED] wrote: I define the class like this: class AAA:     counter = 0     def __init__(self):         pass     def counter_increase():         AAA.counter += 1         print couter

Is there a simple function to generate a list like ['a', 'b', 'c', ... 'z']?

2007-04-09 Thread
Is there a simple function to generate a list like ['a', 'b', 'c', ... 'z']? The range() just can generate the numeric list. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a simple function to generate a list like ['a', 'b', 'c', ... 'z']?

2007-04-09 Thread
On Apr 9, 4:35 pm, Michael Bentley [EMAIL PROTECTED] wrote: On Apr 9, 2007, at 3:29 AM, 人言落日是天涯,望极天涯不 见家 wrote: Is there a simple function to generate a list like ['a', 'b', 'c', ... 'z']?   The range() just can generate the numeric list. import string list(string.lowercase) Thanks

Re: Is there a simple function to generate a list like ['a', 'b', 'c', ... 'z']?

2007-04-09 Thread
On Apr 9, 4:39 pm, Thomas Krüger [EMAIL PROTECTED] wrote: 人言落日是天涯,望极天涯不见家 schrieb: Is there a simple function to generate a list like ['a', 'b', 'c', ... 'z']?   The range() just can generate the numeric list. There is: [ chr(i) for i in range(97, 123) ] Thomas Thanks you too! I'm

how to use the string '\\.\'

2007-04-09 Thread
print r'\\.\' This line will cause error. I just want to print the \\.\ why the prefix character r isn't effective. Thanks! -- http://mail.python.org/mailman/listinfo/python-list