Re: [Tutor] str object is not callable

2012-07-10 Thread Wayne Werner
On Wed, 11 Jul 2012, Steven D'Aprano wrote: Chris Hare wrote: Okay - I am officially embarrassed. [...] Meh, don't beat yourself up too badly. We've all been where you are now. Sometimes I look back at my early Python code... I tell you, that's always a good antidote for a big head. I re

Re: [Tutor] Regular expressions: findall vs search

2012-07-10 Thread Steven D'Aprano
Alexander Q. wrote: My question is how does Python know to return just the part in the parentheses and not to return the "blahblah" and the "yattayattayatta", etc...? The 're.search' function returns the whole thing, and if I want just the parentheses parts, I do tuples.group(1) or tuples.group(

Re: [Tutor] advice on global variables

2012-07-10 Thread Chris Hare
On Jul 10, 2012, at 6:24 PM, Alan Gauld wrote: > On 11/07/12 00:16, Alan Gauld wrote: > >>> One thought was a RAM based SQLite database, but that seems >> > like a lot of work. I dunno, maybe that is the option. >> >> is definitely the best option where the "global" needs to be shared >> acros

Re: [Tutor] advice on global variables

2012-07-10 Thread Alan Gauld
On 11/07/12 00:16, Alan Gauld wrote: One thought was a RAM based SQLite database, but that seems > like a lot of work. I dunno, maybe that is the option. is definitely the best option where the "global" needs to be shared across different programs as well as different modules in a single I

Re: [Tutor] advice on global variables

2012-07-10 Thread Alan Gauld
On 10/07/12 20:11, Chris Hare wrote: I know they are bad. They are not totally bad and most real programs wind up having one or two globals, although usually those globals are top level container classes, perhaps even an Application class or similar. I am not sure how else to handle this pro

Re: [Tutor] advice on global variables

2012-07-10 Thread James Reynolds
Sent from my iPad On Jul 10, 2012, at 3:11 PM, Chris Hare wrote: > > I know they are bad. That is why I would prefer not to use it, but I am not > sure how else to handle this problem. > > In this app, the user must log in. Once authenticated, they have a userid > stored in the SQLite da

Re: [Tutor] advice on global variables

2012-07-10 Thread Prasad, Ramit
> > Just as a note, this would not really work if the variable needs to be > > changed and read from several places when the value is an immutable > > type such as numbers / strings. In that case, then you could use > > the same logic but instead place the value in a list and pass that > > and alwa

Re: [Tutor] advice on global variables

2012-07-10 Thread Alexandre Zani
On Tue, Jul 10, 2012 at 1:32 PM, Prasad, Ramit wrote: >> You should avoid using the global statement. >> >> In your case, I would think you could just add an argument to the method: >> >> class MyObj(object): >> def __init__(self, arg): >> self.arg = arg >> def my_func(self, new_ar

Re: [Tutor] advice on global variables

2012-07-10 Thread James Reynolds
On Tue, Jul 10, 2012 at 4:32 PM, Prasad, Ramit wrote: > > You should avoid using the global statement. > > > > In your case, I would think you could just add an argument to the method: > > > > class MyObj(object): > > def __init__(self, arg): > > self.arg = arg > > def my_func(self

Re: [Tutor] advice on global variables

2012-07-10 Thread Prasad, Ramit
> You should avoid using the global statement. > > In your case, I would think you could just add an argument to the method: > > class MyObj(object): > def __init__(self, arg): > self.arg = arg > def my_func(self, new_arg): > self.arg = new_arg > > to call it: > > arg =

Re: [Tutor] advice on global variables

2012-07-10 Thread Prasad, Ramit
> > > > file: a.py > > > > import b > > global_var = "global" > > > To answer your most basic question: [file b.py] > import a > a.global_var This would be a cyclical import and is bad even if it does not fail. Remove the common dependencies (in this case the global variables) and place it in a

Re: [Tutor] advice on global variables

2012-07-10 Thread James Reynolds
On Tue, Jul 10, 2012 at 3:11 PM, Chris Hare wrote: > > I know they are bad. That is why I would prefer not to use it, but I am > not sure how else to handle this problem. > > In this app, the user must log in. Once authenticated, they have a userid > stored in the SQLite database. Before split

Re: [Tutor] advice on global variables

2012-07-10 Thread Alexandre Zani
On Tue, Jul 10, 2012 at 12:11 PM, Chris Hare wrote: > > I know they are bad. That is why I would prefer not to use it, but I am not > sure how else to handle this problem. > > In this app, the user must log in. Once authenticated, they have a userid > stored in the SQLite database. Before spl

[Tutor] advice on global variables

2012-07-10 Thread Chris Hare
I know they are bad. That is why I would prefer not to use it, but I am not sure how else to handle this problem. In this app, the user must log in. Once authenticated, they have a userid stored in the SQLite database. Before splitting my app into multiple files, I used a global variable.

Re: [Tutor] Regular expressions: findall vs search

2012-07-10 Thread Hugo Arts
On Tue, Jul 10, 2012 at 9:26 PM, Alexander Q. wrote: > I'm a bit confused about extracting data using re.search or re.findall. > > Say I have the following code: tuples = > re.findall(r'blahblah(\d+)yattayattayatta(\w+)moreblahblahblah(\w+)over', > text) > > So I'm looking for that string in 'tex

[Tutor] Regular expressions: findall vs search

2012-07-10 Thread Alexander Q.
I'm a bit confused about extracting data using re.search or re.findall. Say I have the following code: tuples = re.findall(r'blahblah(\d+)yattayattayatta(\w+)moreblahblahblah(\w+)over', text) So I'm looking for that string in 'text', and I intend to extract the parts which have parentheses around

Re: [Tutor] str object is not callable

2012-07-10 Thread Steven D'Aprano
Chris Hare wrote: Okay - I am officially embarrassed. [...] Meh, don't beat yourself up too badly. We've all been where you are now. Sometimes I look back at my early Python code... I tell you, that's always a good antidote for a big head. -- Steven _

Re: [Tutor] str object is not callable

2012-07-10 Thread Chris Hare
Okay - I am officially embarrassed. As you might now, I am splitting this 10,000 line file apart, and that is posing certain challenges which I am fixing, and cleaning up stuff that was broken and visible only when doing this split. This is one of them. What I failed to remember -- and y

Re: [Tutor] str object is not callable

2012-07-10 Thread Steven D'Aprano
Chris Hare wrote: def special_match(string, search=re.compile(r'[^a-zA-Z0-9\.\ \-\#\$\*\@\!\%\^\&]').search): #string = string.rstrip() return not bool(search(string)) The call to bool is redundant. Get rid of it. The not operator will automatically convert its argument into a

Re: [Tutor] str object is not callable

2012-07-10 Thread Brian van den Broek
On 10 Jul 2012 11:31, "Chris Hare" wrote: > > > This piece of code works: > > Big-Mac:Classes chare$ more tmp.py > import re > > return not bool(search(string)) > However, when I use the EXACT same code in the context of the larger code, I get the error > > return not bool(search

Re: [Tutor] Examples of "With....As Statement" in Python

2012-07-10 Thread Steven D'Aprano
James Bell wrote: I'm attempting to learn how to use the "withas" statement in python. I've read the documentation and also a few tutorials but I still cannot understand the concept. or how this is normally used. Can someone please write an example or 2 of simple ways to use the "with statem

Re: [Tutor] str object is not callable

2012-07-10 Thread Prasad, Ramit
> This piece of code works: > > Big-Mac:Classes chare$ more tmp.py > import re > > def special_match(string, search=re.compile(r'[^a-zA-Z0-9\.\ \- > \#\$\*\@\!\%\^\&]').search): > #string = string.rstrip() > return not bool(search(string)) > > print special_match("admin") > print

Re: [Tutor] str object is not callable

2012-07-10 Thread Dave Angel
On 07/10/2012 10:56 AM, Chris Hare wrote: > This piece of code works: > > Big-Mac:Classes chare$ more tmp.py > import re > > def special_match(string, search=re.compile(r'[^a-zA-Z0-9\.\ > \-\#\$\*\@\!\%\^\&]').search): > #string = string.rstrip() > return not bool(search(string)) Y

Re: [Tutor] Examples of "With....As Statement" in Python

2012-07-10 Thread mariocatch
On Tue, Jul 10, 2012 at 11:25 AM, Mark Lawrence wrote: > On 10/07/2012 15:58, James Bell wrote: > >> I'm attempting to learn how to use the "withas" statement in python. >> >> I've read the documentation and also a few tutorials but I still cannot >> understand the concept. or how this is norm

Re: [Tutor] str object is not callable

2012-07-10 Thread Devin Jeanpierre
On Tue, Jul 10, 2012 at 10:56 AM, Chris Hare wrote: > The input to the function in the larger program is the same as the first test > in the small script that works -- "admin". > > As a side note -- the rstrip call is also broken, although the string module > is imported. I just can't figure ou

Re: [Tutor] Examples of "With....As Statement" in Python

2012-07-10 Thread Mark Lawrence
On 10/07/2012 15:58, James Bell wrote: I'm attempting to learn how to use the "withas" statement in python. I've read the documentation and also a few tutorials but I still cannot understand the concept. or how this is normally used. Can someone please write an example or 2 of simple ways to

[Tutor] str object is not callable

2012-07-10 Thread Chris Hare
This piece of code works: Big-Mac:Classes chare$ more tmp.py import re def special_match(string, search=re.compile(r'[^a-zA-Z0-9\.\ \-\#\$\*\@\!\%\^\&]').search): #string = string.rstrip() return not bool(search(string)) print special_match("admin") print special_match("&!*") p

[Tutor] Examples of "With....As Statement" in Python

2012-07-10 Thread James Bell
I'm attempting to learn how to use the "withas" statement in python. I've read the documentation and also a few tutorials but I still cannot understand the concept. or how this is normally used. Can someone please write an example or 2 of simple ways to use the "with statement". I understand

Re: [Tutor] confusion about imports

2012-07-10 Thread Mark Lawrence
On 10/07/2012 03:04, Steven D'Aprano wrote: Mark Lawrence wrote: On 09/07/2012 16:56, Chris Hare wrote: So, I have to admit, imports have me really confused. I am trying to break apart a 10,000+ line single file into various files Please don't break the file up for the sake of doing it, you

Re: [Tutor] updating step size while in loop

2012-07-10 Thread Alan Gauld
On 09/07/12 22:59, Abhishek Pratap wrote: I want to know whether it is possible for dynamically update the step size in xrange or someother slick way. Here is what I am trying to do, if during a loop I find the x in list I want to skip next #n iterations. You could use the next() method of t