Re: [Tutor] Notepad++ question

2012-06-06 Thread Dave Angel
On 06/07/2012 12:29 AM, Alexander Quest wrote: > Hey all; my question is regarding editing Python code in Notepad++. When I > run this piece of code in Notepad++: > > def fix_start(s): > var1 = s[0] > var2 = "*" > var3 = s.replace(var1, var2) > > return var3 > > > I get an indentation err

[Tutor] Notepad++ question

2012-06-06 Thread Alexander Quest
Hey all; my question is regarding editing Python code in Notepad++. When I run this piece of code in Notepad++: def fix_start(s): var1 = s[0] var2 = "*" var3 = s.replace(var1, var2) return var3 I get an indentation error, which reads: File "C:\google-python-exercises\google-python

Re: [Tutor] Searching 2 Strings in A File

2012-06-06 Thread Alan Gauld
On 06/06/12 20:33, dohoang4...@comcast.net wrote: i am writing a python script that will be invoked as follows: cmd_line = Popen(["egrep", "(x,y)", aLogFile], stdout=PIPE, stdin=PIPE, stderr=STDOUT) Assuming you really want to use egrep, why? You could process the file directly in Python sea

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Alan Gauld
On 06/06/12 21:32, Dave wrote: I'm not sure where this comment belongs, but I want to share my perspective on the documentation of these special method names. In the following section there is an inconsistency which could be confusing to someone just learning Python (e.g., me). In general someo

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Steven D'Aprano
Dave wrote: I was reading some tutorial material on creating iterators. It shows the following example implementation of an iterator: class Reverse: """Iterator for looping over a sequence backwards.""" def __init__(self, data): self.data = data self.index = len(data)

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Steven D'Aprano
Prasad, Ramit wrote: That is, for loops first try to build an iterator by calling __iter__, and if that fails they try the sequence protocol obj[0], obj[1], obj[2], ... So...I could instead write __getitem__ for the same effect? Er, no... __getitem__ and __iter__ do very different things. __

Re: [Tutor] Joining all strings in stringList into one string

2012-06-06 Thread Steven D'Aprano
Prasad, Ramit wrote: But more importantly, some years ago (Python 2.4, about 8 years ago?) the Python developers found a really neat trick that they can do to optimize string concatenation so it doesn't need to repeatedly copy characters over and over and over again. I won't go into details, but

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Prasad, Ramit
> That is, for loops first try to build an iterator by calling __iter__, and if > that fails they try the sequence protocol obj[0], obj[1], obj[2], ... So...I could instead write __getitem__ for the same effect? Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Mai

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Steven D'Aprano
Prasad, Ramit wrote: For instance, the __iter__() method is called by the iter() built-in. It can also called by any other piece of code that needs to acquire an iterator from a generic container object. There is no list of all such pieces of code that could ever call the __iter__() method of yo

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Prasad, Ramit
> For instance, the __iter__() method is called by the iter() built-in. > It can also called by any other piece of code that needs to acquire an > iterator from a generic container object. There is no list of all > such pieces of code that could ever call the __iter__() method of your A lot of ti

Re: [Tutor] Searching 2 Strings in A File

2012-06-06 Thread Prasad, Ramit
Please respond back to the list (so others know what worked and that the problem is solved). :) > > hi all, > > thanks a lot for your quick response. > > Dave, actually it's a 2 arguments.  Sorry, i did not make it clear in my > question.  I used Ramit's hint and it worked.  The code should

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Jerry Hill
On Wed, Jun 6, 2012 at 4:32 PM, Dave wrote: > I'm not sure where this comment belongs, but I want to share my perspective > on the documentation of these special method names. In the following section > there is an inconsistency which could be confusing to someone just learning > Python (e.g., me)

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Dave
I'm not sure where this comment belongs, but I want to share my perspective on the documentation of these special method names. In the following section there is an inconsistency which could be confusing to someone just learning Python (e.g., me). In the sentence on implementing custom mapping obj

Re: [Tutor] Searching 2 Strings in A File

2012-06-06 Thread Prasad, Ramit
> > x = "Device " + sys.argv[1] + " restored the database" > > y = "Created connection to " + sys.argv[1] > > > > cmd_line = Popen(["egrep", "(x,y)", aLogFile], stdout=PIPE, stdin=PIPE, > > stderr=STDOUT) > > > > the above code does not work because it will look for x and y in aLogFile

Re: [Tutor] Searching 2 Strings in A File

2012-06-06 Thread Prasad, Ramit
> x = "Device " + sys.argv[1] + " restored the database" > y = "Created connection to " + sys.argv[1] > > cmd_line = Popen(["egrep", "(x,y)", aLogFile], stdout=PIPE, stdin=PIPE, > stderr=STDOUT) > > the above code does not work because it will look for x and y in aLogFile > instead of

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Dave
On Wed, Jun 6, 2012 at 3:40 PM, Mark Lawrence wrote: > On 06/06/2012 20:19, Dave wrote: > >> I was reading some tutorial material on creating iterators. It shows the >> following example implementation of an iterator: >> >> class Reverse: >> """Iterator for looping over a sequence backwards.""

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Dave
On Wed, Jun 6, 2012 at 3:30 PM, Prasad, Ramit wrote: > > My question is how was I supposed to kinow that the function I call > using the > > name iter() is implemented using the name __iter__()? > > > > Is there a rule that describes when I would implement an attribute name > with > > leading and

Re: [Tutor] Searching 2 Strings in A File

2012-06-06 Thread Dave Angel
On 06/06/2012 03:33 PM, dohoang4...@comcast.net wrote: > i am writing a python script that will be invoked as follows: > > myScript.py > > and the script is as follwos: > > x = "Device " + sys.argv[1] + " restored the database" > y = "Created connection to " + sys.argv[1] > > cmd_line = Popen

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Mark Lawrence
On 06/06/2012 20:19, Dave wrote: I was reading some tutorial material on creating iterators. It shows the following example implementation of an iterator: class Reverse: """Iterator for looping over a sequence backwards.""" def __init__(self, data): self.data = data s

Re: [Tutor] sqlite3 Question

2012-06-06 Thread Prasad, Ramit
> > 1. import sqlite3 > 2. conn=sqlite3.connect("mydb2.db") > 3. c=conn.cursor() > 4. c.execute('create table family (Id integer primary key, name text, age > integer)') > 5. c.execute("insert into family values (1,'elham',32)") > 6. c.execute('select * from family') > 7. conn.commit() > 8. for i

[Tutor] Searching 2 Strings in A File

2012-06-06 Thread dohoang4093
i am writing a python script that will be invoked as follows: myScript.py and the script is as follwos: x = "Device " + sys.argv[1] + " restored the database" y = "Created connection to " + sys.argv[1] cmd_line = Popen(["egrep", "(x,y)", aLogFile], stdout=PIPE, stdin=PIPE, stderr=STDOUT)

Re: [Tutor] special attributes naming confusion

2012-06-06 Thread Prasad, Ramit
> My question is how was I supposed to kinow that the function I call using the > name iter() is implemented using the name __iter__()? > > Is there a rule that describes when I would implement an attribute name with > leading and trailing double underscores, and then call it without those > under

[Tutor] sqlite3 Question

2012-06-06 Thread Khalid Al-Ghamdi
Hi All, hi Joel, Regarding sqlite3 practice code below: 1. import sqlite3 2. conn=sqlite3.connect("mydb2.db") 3. c=conn.cursor() 4. c.execute('create table family (Id integer primary key, name text, age integer)') 5. c.execute("insert into family values (1,'elham',32)") 6.

[Tutor] special attributes naming confusion

2012-06-06 Thread Dave
I was reading some tutorial material on creating iterators. It shows the following example implementation of an iterator: class Reverse: """Iterator for looping over a sequence backwards.""" def __init__(self, data): self.data = data self.index = len(data) def __iter__(

Re: [Tutor] Python 2.7 Static Version and Postgresql

2012-06-06 Thread Opher Lubzens
On Tue, May 29, 2012 at 9:26 PM, Opher Lubzens wrote: > > That actually might be workable- I'll have to look into it. I'll have > to understand them better then I do after a brief look in their > webpages and check whether they're compatible with our specific flavor > of OS, since both of these ar

Re: [Tutor] connecting to USB

2012-06-06 Thread BILAL Mustapha
Le 06/06/2012 11:02, BILAL Mustapha a écrit : Hello, I am working to connect to a serial link (USB). In order to do that I have to write this command: sudo ../../tools/stm32w/serialdump-linux -b115200 -d1 (keeping in mind dat*serialdump-linux*, which is in the path, is not a folder, it

Re: [Tutor] The dreaded UnicodeDecodeError... why, why, why does it still want ascii?

2012-06-06 Thread Stefan Behnel
Marc Tompkins, 06.06.2012 10:21: > On Tue, Jun 5, 2012 at 11:22 PM, Stefan Behnel wrote: > >> You can do this: >> >>connection = urllib2.urlopen(url) >>tree = etree.parse(connection, my_html_parser) >> >> Alternatively, use fromstring() to parse from strings: >> >>page = urllib2.urlope

[Tutor] connecting to USB

2012-06-06 Thread BILAL Mustapha
Hello, I am working to connect to a serial link (USB). In order to do that I have to write this command: sudo ../../tools/stm32w/serialdump-linux -b115200 -d1 (keeping in mind dat*serialdump-linux*, which is in the path, is not a folder, it's an executable) To get to the root, I have

Re: [Tutor] The dreaded UnicodeDecodeError... why, why, why does it still want ascii?

2012-06-06 Thread Marc Tompkins
On Tue, Jun 5, 2012 at 11:22 PM, Stefan Behnel wrote: > You can do this: > >connection = urllib2.urlopen(url) >tree = etree.parse(connection, my_html_parser) > > Alternatively, use fromstring() to parse from strings: > >page = urllib2.urlopen(url) >pagecontents = page.read() >

Re: [Tutor] error_connection_refused

2012-06-06 Thread BILAL Mustapha
Hello, Thank you for your reply. Please read underlines. Le 05/06/2012 23:12, Alan Gauld a écrit : On 05/06/12 12:53, BILAL Mustapha wrote: Hello, Hi, Its best not to hijack somebody else's thread coz it messes up all the threaded mail/news readers out there. (At least you changed the s