Re: [Tutor] Confusion regarding the 'from' statement

2012-08-14 Thread eryksun
On Tue, Aug 14, 2012 at 9:04 PM, Dave Angel wrote: > > 1) recursive imports. If anybody has a non-trivial top-level code, or > even certain class-initialization code, this can cause surprising errors. Yes, it's a problem if you try to "from" import an object that hasn't been defined yet or use

Re: [Tutor] Confusion regarding the 'from' statement

2012-08-14 Thread Dave Angel
On 08/14/2012 04:00 PM, eryksun wrote: > On Tue, Aug 14, 2012 at 2:24 PM, Mazhar Hussain wrote: >> #mod1.py >> from mod2 import test >> test('mod1.py') >> >> #mod2.py >> def countLines(name): >> print len(open(name).readlines()) >> >> def countChars(name): >> print len(open(name).read()) >

Re: [Tutor] Resource question?

2012-08-14 Thread Lisa Jervis
On 8/14/12 3:57 PM, Scurvy Scott wrote: Hello, I'm totally new to this list. I've been learning python through codecademy.com which has een helping a lot with it's step by step approach. I'm wondering if there are any others like it? I've been looking at some other pl

Re: [Tutor] overriding instance attributes with keywords

2012-08-14 Thread Steven D'Aprano
On 15/08/12 04:25, Matt Gregory wrote: Thanks to you both for really helpful advice. A quick follow-up question - would you want to create a deepcopy of obj1 in the above example if your obj1 contained other objects? Only the person making the copy can answer that question, but in general,

Re: [Tutor] Resource question?

2012-08-14 Thread Alan Gauld
On 14/08/12 23:57, Scurvy Scott wrote: I've been learning python through codecademy.com which has een helping a lot with it's step by step approach. I'm wondering if there are any others like it? I've been looking at some other places that attempt to teach python (google

Re: [Tutor] How do I fix this?

2012-08-14 Thread Lily Tran
I figure out how to do this. Here is the code that would allow me to print 320 to 321: def WhereAreNumbers(a_list): numberString='' for index, element in enumerate(a_list): if element.isdigit(): numberString += element else: if numberString != "

[Tutor] Resource question?

2012-08-14 Thread Scurvy Scott
Hello, I'm totally new to this list. I've been learning python through codecademy.com which has een helping a lot with it's step by step approach. I'm wondering if there are any others like it? I've been looking at some other places that attempt to teach python (google python course, code kata or

Re: [Tutor] How do I fix this?

2012-08-14 Thread Alan Gauld
On 14/08/12 23:30, Lily Tran wrote: I have 320 dollars to buy grocery. My program would print out: I have 321 to buy grocery. However, the code that I have listed below would print out: I have 431 dollars to buy grocery. How do I fix this program so that it print out 321 vs. 431? Since this

[Tutor] How do I fix this?

2012-08-14 Thread Lily Tran
I am trying to read in a string from the user input and if the string is a number then I would print out the numbers + 1. For example if the user enters: I have 320 dollars to buy grocery. My program would print out: I have 321 to buy grocery. However, the code that I have listed below would

Re: [Tutor] Confusion regarding the 'from' statement

2012-08-14 Thread eryksun
On Tue, Aug 14, 2012 at 2:24 PM, Mazhar Hussain wrote: > > #mod1.py > from mod2 import test > test('mod1.py') > > #mod2.py > def countLines(name): > print len(open(name).readlines()) > > def countChars(name): > print len(open(name).read()) > > def test(name): > print 'loading...' >

Re: [Tutor] Confusion regarding the 'from' statement

2012-08-14 Thread Peter Otten
Mazhar Hussain wrote: > Im new to python and theres something thats bothering me for quite a > time. I read in 'Learning Python' by Mark Lutz that when we use a > 'from' statement to import a name present in a module, it first > imports the module then assigns a new name to it(i.e. the name of the

Re: [Tutor] Confusion regarding the 'from' statement

2012-08-14 Thread Joel Goldstick
On Tue, Aug 14, 2012 at 2:43 PM, David Rock wrote: > * Mazhar Hussain [2012-08-14 23:24]: >> the module object with the del statement. However what happens if I >> try to import a name using 'from' that references a name in the >> imported module that itself is not imported. Consider the followin

Re: [Tutor] overriding instance attributes with keywords

2012-08-14 Thread eryksun
On Tue, Aug 14, 2012 at 2:25 PM, Matt Gregory wrote: > > Thanks to you both for really helpful advice. A quick follow-up question - > would you want to create a deepcopy of obj1 in the above example if your > obj1 contained other objects? I think that Steven's class method gets > around this? C

Re: [Tutor] Confusion regarding the 'from' statement

2012-08-14 Thread David Rock
* Mazhar Hussain [2012-08-14 23:24]: > the module object with the del statement. However what happens if I > try to import a name using 'from' that references a name in the > imported module that itself is not imported. Consider the following > example,here there are two modules mod1.py and mod2.p

Re: [Tutor] Matching 3 tables with almost identical columns

2012-08-14 Thread Mark Lawrence
On 14/08/2012 17:53, Steven D'Aprano wrote: What is asciitable? Just for the record http://pypi.python.org/pypi/asciitable/0.8.0 -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http:

Re: [Tutor] overriding instance attributes with keywords

2012-08-14 Thread Matt Gregory
On 8/14/2012 5:28 AM, eryksun wrote: On Tue, Aug 14, 2012 at 6:01 AM, eryksun wrote: Right, I overlooked classes with __slots__ and that override __new__ and other special methods. copy() is the better and more customizable solution. If copying is good enough, then this should work: from co

[Tutor] Confusion regarding the 'from' statement

2012-08-14 Thread Mazhar Hussain
Im new to python and theres something thats bothering me for quite a time. I read in 'Learning Python' by Mark Lutz that when we use a 'from' statement to import a name present in a module, it first imports the module then assigns a new name to it(i.e. the name of the function,class, etc present in

Re: [Tutor] Matching 3 tables with almost identical columns

2012-08-14 Thread Steven D'Aprano
Hi Elaina, My comments interleaved with yours. If you read nothing else, scroll down and read my last paragraph. Good luck! On 13/08/12 17:24, Elaina Ann Hyde wrote: Greetings, I have a rather monolithic database I am re-building at the moment, and I want to join 3 tables with semi-matc

Re: [Tutor] output not in ANSI, conversing char set to locale.getpreferredencoding()

2012-08-14 Thread Walter Prins
Hi Leon, Since Unicode's been pulled into the discussion, I'd like to suggest you watch and read the following presentation "Pragmatic Unicode ~or~ How do I stop the pain?" from Pycon US 2012: http://nedbatchelder.com/text/unipain.html Walter ___ Tutor

Re: [Tutor] output not in ANSI, conversing char set to locale.getpreferredencoding()

2012-08-14 Thread eryksun
On Tue, Aug 14, 2012 at 10:03 AM, Peter Otten <__pete...@web.de> wrote: > > You have to find out the database encoding The character at 7 is 'ë', which is '\xc3\xab' in UTF-8. So that's likely the db encoding. > As you now have a bytestring again you can forget about codecs.open() which > won't w

Re: [Tutor] output not in ANSI, conversing char set to locale.getpreferredencoding()

2012-08-14 Thread Peter Otten
leon zaat wrote: > I get the error: > UnicodeDecodeError: 'ascii' codecs can't decode byte 0xc3 in position 7: > ordinal not in range(128) for the openbareruimtenaam=u'' + > (openbareruimtenaam1.encode(chartype)) line. The error message means that database.select() returns a byte string. bytest

Re: [Tutor] output not in ANSI, conversing char set to locale.getpreferredencoding()

2012-08-14 Thread leon zaat
> From: eryk...@gmail.com > Date: Mon, 13 Aug 2012 15:12:04 -0400 > To: joel.goldst...@gmail.com > CC: alan.ga...@btinternet.com; tutor@python.org > Subject: Re: [Tutor] output not in ANSI > > On Mon, Aug 13, 2012 at 2:04 PM, Joel Goldstick > wrote: > > > > I believe in this context the OP mea

Re: [Tutor] overriding instance attributes with keywords

2012-08-14 Thread eryksun
On Tue, Aug 14, 2012 at 6:01 AM, eryksun wrote: > > Right, I overlooked classes with __slots__ and that override __new__ > and other special methods. copy() is the better and more customizable > solution. If copying is good enough, then this should work: from copy import copy def copy_with_over

Re: [Tutor] overriding instance attributes with keywords

2012-08-14 Thread eryksun
On Mon, Aug 13, 2012 at 10:28 PM, Steven D'Aprano wrote: > >> def new_with_overrides(obj1, **kwds): >> obj2 = obj1.__new__(obj1.__class__) >> obj2.__dict__.update(obj1.__dict__) >> for k, v in kwds.items(): >> if k in obj2.__dict__: >> obj2.__dict__[k] = v >>