Re: [Tutor] odd behavior when renaming a file

2012-05-10 Thread Joel Goldstick
On Thu, May 10, 2012 at 5:05 PM, Prasad, Ramit wrote: >> I have to process a csv file from a business partner.  Oddly (?) they >> don't quote text fields, and the Title field sometimes contains >> commas.  So I wrote some code to count the commas in each line and if >> there were too many, I remov

Re: [Tutor] odd behavior when renaming a file

2012-05-10 Thread Prasad, Ramit
> I have to process a csv file from a business partner. Oddly (?) they > don't quote text fields, and the Title field sometimes contains > commas. So I wrote some code to count the commas in each line and if > there were too many, I removed the extras and wrote the cleaned up > file to the origin

Re: [Tutor] odd behavior when renaming a file

2012-05-10 Thread Alan Gauld
On 10/05/12 21:18, Dave Angel wrote: out_file = open('revelex.csv', 'w') # etc. I would expect the open() to fail... But he's opening it for WRITE, so it gets created just fine. Ah yes, I didn't spot that. :-) Too busy looking for a possible cause of a missing file message...

Re: [Tutor] odd behavior when renaming a file

2012-05-10 Thread Joel Goldstick
On Thu, May 10, 2012 at 4:18 PM, Dave Angel wrote: > On 05/10/2012 12:56 PM, Alan Gauld wrote: >> On 09/05/12 20:26, Joel Goldstick wrote: >>> import os >>> def pre_process(): >>>      if os.path.isfile('revelex.csv'): >>>          os.rename('revelex.csv', 'revelex.tmp') >>>          print "Rename

Re: [Tutor] odd behavior when renaming a file

2012-05-10 Thread Dave Angel
On 05/10/2012 12:56 PM, Alan Gauld wrote: > On 09/05/12 20:26, Joel Goldstick wrote: >> import os >> def pre_process(): >> if os.path.isfile('revelex.csv'): >> os.rename('revelex.csv', 'revelex.tmp') >> print "Renamed ok" >> else: >> print "Exiting, no revelex.c

Re: [Tutor] odd behavior when renaming a file

2012-05-10 Thread Joel Goldstick
On Wed, May 9, 2012 at 5:21 PM, Peter Otten <__pete...@web.de> wrote: > Joel Goldstick wrote: > >> import os >> def pre_process(): >>     if os.path.isfile('revelex.csv'): >>         os.rename('revelex.csv', 'revelex.tmp') >>         print "Renamed ok" >>     else: >>         print "Exiting, no rev

Re: [Tutor] odd behavior when renaming a file

2012-05-10 Thread Alan Gauld
On 09/05/12 20:26, Joel Goldstick wrote: import os def pre_process(): if os.path.isfile('revelex.csv'): os.rename('revelex.csv', 'revelex.tmp') print "Renamed ok" else: print "Exiting, no revelex.csv file available" exit() out_file = open('revele

Re: [Tutor] odd behavior when renaming a file

2012-05-09 Thread Peter Otten
Joel Goldstick wrote: > import os > def pre_process(): > if os.path.isfile('revelex.csv'): > os.rename('revelex.csv', 'revelex.tmp') > print "Renamed ok" > else: > print "Exiting, no revelex.csv file available" > exit() > out_file = open('revelex.csv', '

Re: [Tutor] odd behavior when renaming a file

2012-05-09 Thread Walter Prins
Hi, On 9 May 2012 20:26, Joel Goldstick wrote: > import os > def pre_process(): >if os.path.isfile('revelex.csv'): >os.rename('revelex.csv', 'revelex.tmp') >print "Renamed ok" >else: >print "Exiting, no revelex.csv file available" >exit() >out_file = o

[Tutor] odd behavior when renaming a file

2012-05-09 Thread Joel Goldstick
import os def pre_process(): if os.path.isfile('revelex.csv'): os.rename('revelex.csv', 'revelex.tmp') print "Renamed ok" else: print "Exiting, no revelex.csv file available" exit() out_file = open('revelex.csv', 'w') # etc. if __name__ == '__main__'

Re: [Tutor] Odd behavior with eval, list comps, and name lookup

2011-02-18 Thread Peter Otten
John wrote: > I noticed some odd behavior relating to eval(). First, a baseline case for > behavior: > def test(): > ... x = 5 > ... return [a for a in range(10) if a == x] > ... test() > [5] > > So far so good. Now let's try eval: > c = compile('[a for a in range(10) if a == x]'

[Tutor] Odd behavior with eval, list comps, and name lookup

2011-02-18 Thread John
I noticed some odd behavior relating to eval(). First, a baseline case for behavior: >>> def test(): ... x = 5 ... return [a for a in range(10) if a == x] ... >>> test() [5] So far so good. Now let's try eval: >>> c = compile('[a for a in range(10) if a == x]', '', 'single') >>> eval(c, globals(

Re: [Tutor] Odd result from function call

2011-01-07 Thread Alan Gauld
"Ben Ganzfried" wrote x = input("First x is: ") y = input("First y is: ") input() reads strings compare(x,y) the character '1' is less than the character '5' so far as Python is concerned When I do simply compare(10, 5) from the shell, You are using integers. What happens if you u

Re: [Tutor] Odd result from function call

2011-01-07 Thread Alex Hall
Cast to an int: x=int(x) See if that helps. On 1/7/11, Ben Ganzfried wrote: > When I call one of my functions from the shell (ie compare(10, 5)) it > produces the correct output. However, when I run the program after calling > the method later in the script, the result is bizarre. I'm curious w

Re: [Tutor] Odd result from function call

2011-01-07 Thread Vince Spicer
On Fri, Jan 7, 2011 at 11:38 AM, Ben Ganzfried wrote: > When I call one of my functions from the shell (ie compare(10, 5)) it > produces the correct output. However, when I run the program after calling > the method later in the script, the result is bizarre. I'm curious why the > wrong result i

[Tutor] Odd result from function call

2011-01-07 Thread Ben Ganzfried
When I call one of my functions from the shell (ie compare(10, 5)) it produces the correct output. However, when I run the program after calling the method later in the script, the result is bizarre. I'm curious why the wrong result is printed. Here is an example: def compare(x,y): if x < y

Re: [Tutor] odd bug

2007-07-20 Thread christopher . henk
phone: 317.242.2569 fax: 317.242.3469 e-mail: [EMAIL PROTECTED] "elis aeris" <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] 07/20/2007 02:36 AM To "Luke Paireepinart" <[EMAIL PROTECTED]> cc python tutor Subject [Tutor] odd bug I ran the code attache

[Tutor] odd bug

2007-07-19 Thread elis aeris
I ran the code attached at the end of the email, it' supposed to out put a string of characters, yet I got only this ### 2.4.3.3.8.5. definition check: 3 ### now, it's proper output, however, this part got run only once, when it's supposed to run multiple times to produce more portio

Re: [Tutor] odd

2007-07-18 Thread Ian Witham
from Guido's tutorial: The given end point is never part of the generated list; range(10) generates a list of 10 values, the legal indices for items of a sequence of length 10. It is possible to let the range start at another number, or to specify a different increment (even negative; sometimes t

Re: [Tutor] odd

2007-07-18 Thread David Rock
* elis aeris <[EMAIL PROTECTED]> [2007-07-19 08:51]: > I ran this > > > for x in range(5,10): >print x > > and OP was > > 5 > 6 > 7 > 8 > 9 > > why is that? shouldn't it print > > 5 > 6 > 7 > 8 > 9 > 10? That is the expected behaviour, per the documentation: http://docs.python.org/lib/bu

Re: [Tutor] odd

2007-07-18 Thread wesley chun
> for x in range(5,10): > print x > > and OP was > > 5 > 6 > 7 > 8 > 9 > > why is that? shouldn't it print > > t > 6 > 7 > 8 > 9 > 10? no. the (well, one) syntax for range() is (start, stop) where it counts starting from 'start' up to but not including 'stop'. if you're familiar with C/C++

[Tutor] odd

2007-07-18 Thread elis aeris
I ran this for x in range(5,10): print x and OP was 5 6 7 8 9 why is that? shouldn't it print t 6 7 8 9 10? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Odd traceback - invalid token when extracting contents of XML data element

2006-06-12 Thread Andrew Robert
Hi Everyone, Attached are three scripts that I intend to use for transporting a file via IBM's WebSphere MQSeries middle-ware. The sender script uses a regular expression to replace characters not [a-z][A-Z][0-9] or white space with their hex value equivalents. The purpose of this is to make the

[Tutor] odd behavior within __init__

2005-04-15 Thread Jeff Shannon
(Oops, forgot to change this to go to the list...) On 4/14/05, Orri Ganel <[EMAIL PROTECTED]> wrote: > On 4/14/05, Rich Krauter <[EMAIL PROTECTED]> wrote: > > On 4/14/05, Max Noel <[EMAIL PROTECTED]> wrote: > >Well, if you want b and a to refer to the same object, just use b = > > a. > >

Re: [Tutor] odd behavior within __init__

2005-04-14 Thread Orri Ganel
On 4/14/05, Rich Krauter <[EMAIL PROTECTED]> wrote: > Maybe you could use a factory. It would allow you to simplify your Node > class, and encapsulate the instantiation behavior you want outside the > class. Thanks for the suggestion; I think that's what I'll do. On 4/14/05, Max Noel <[EMAIL PRO

Re: [Tutor] odd behavior within __init__

2005-04-14 Thread Rich Krauter
Orri Ganel wrote: Hello all, As part of a project i'm doing (mostly for the fun of it), I have a class which creates a sort of wrapper around any object to make it suitable for use in a custom container. However, if the class receives an already wrapped object, I want it to just return the object

Re: [Tutor] odd behavior within __init__

2005-04-14 Thread Max Noel
On Apr 14, 2005, at 12:58, Orri Ganel wrote: a = Node(1) b = Node(a) 12932600 12932600 1 id(b) 12960632 Any ideas on why this happens, or suggestions as to how to implement the behavior I'm looking for (in which b and a would refer to the same object, have the same id, etc.), would be greatly appre

[Tutor] odd behavior within __init__

2005-04-14 Thread Orri Ganel
Hello all, As part of a project i'm doing (mostly for the fun of it), I have a class which creates a sort of wrapper around any object to make it suitable for use in a custom container. However, if the class receives an already wrapped object, I want it to just return the object (same id and ever

Re: [Tutor] Odd problem with variable substitution and command execution

2005-04-13 Thread Kent Johnson
Robert, Andrew wrote: Hi Everyone, I am trying to do an MQ inquiry but I am having mixed results. If I do the command direct via a print statement like the one below, it works, print 'Queue Description:\t' , q.inquire(CMQC.MQCA_Q_DESC) When I try to cycle through an array of command line supplied k

[Tutor] Odd problem with variable substitution and command execution

2005-04-13 Thread Robert, Andrew
Hi Everyone, I am trying to do an MQ inquiry but I am having mixed results. If I do the command direct via a print statement like the one below, it works, print 'Queue Description:\t' , q.inquire(CMQC.MQCA_Q_DESC) When I try to cycle through an array of command line supplied keys, it fails.