[Tutor] Re: Tutor Digest, Vol 7, Issue 30

Chuck csm1 at academicplanet.com
Wed Feb 11 22:00:29 EST 2004


Magnus,

Thank you for replying.

I don't understand it, but you were right!  When I start IDLE by
double-clicking on the shortcut to it (C:\Python23\pythonw.exe
"C:\PYTHON23\Lib\idlelib\idle.pyw"), the shell opens with this:

IDLE 1.0.2
>>>

If I then open a .py file and select "Run Module", it "hangs" as I described
previously, and shows ----- RESTART-----.

However, if I open the .py file by right-clicking on it and selecting "Edit
with IDLE", the shell opens with this:

IDLE 1.0.2      ==== No Subprocess ====
>>>

...and when I click on "Run Module", it runs fine - without
"-----RESTART-----"

Incidentally, I am running Windows 98 SE on a computer with a 333 MHz
Celeron, so that could be part of the problem.

Regarding running scripts from a command prompt, how do you do that?  I
tried entering the path to the .py file, in the RUN line, but that ran the
script quickly and closed the MS-DOS window.  What DOS command do you use to
run a .py file?

Thanks,

Chuck

----- Original Message ----- 
From: <tutor-request at python.org>
To: <tutor at python.org>
Sent: Wednesday, February 11, 2004 4:39 PM
Subject: Tutor Digest, Vol 7, Issue 30


> Send Tutor mailing list submissions to
> tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-request at python.org
>
> You can reach the person managing the list at
> tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>    1. Re: very basic question from a newbie (Magnus Lycka)
>    2. Pulling data from a DBaseIV file (Andrew Eidson)
>    3. Re: Pulling data from a DBaseIV file (Lloyd Kvam)
>    4. Re: Pulling data from a DBaseIV file (Bob Gailer)
>    5. Re: Pulling data from a DBaseIV file (Andrew Eidson)
>    6. time arithmetic with 2.3 datetime module (Jeff Kowalczyk)
>    7. Re: Pulling data from a DBaseIV file (Andrew Eidson)
>    8. Re: {Spam?} Re: [Tutor] Pulling data from a DBaseIV file
>       (Bob Gailer)
>    9. readline() problem (Ron Alvarado)
>   10. Re: readline() problem (hcohen2)
>   11. Re: readline() problem (Marilyn Davis)
>   12. Re: time arithmetic with 2.3 datetime module (Karl Pfl?sterer )
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 11 Feb 2004 18:49:44 +0100
> From: Magnus Lycka <magnus at thinkware.se>
> Subject: Re: [Tutor] very basic question from a newbie
> To: Chuck Marshall <csm1 at academicplanet.com>, tutor at python.org
> Message-ID: <think001_402a65b94a316 at webmail.thinkware.se>
> Content-Type: TEXT/plain; CHARSET=iso-8859-1
>
> > I just read "IDLE Introduction --- One Day of IDLE Toying".  It was
great because it was so basic and helped me get started.  My first couple of
test "modules" ran just fine, but all of a sudden IDLE started "hanging" for
a long time every time I click on "Run Module".  Just running the following
module seems to freeze the video on my computer for about 15 seconds.
>
> In my experience, IDLE gets slow if there is a lot of data, particularly
> long lines of text, in the interactive interpreter window. It doesn't
> matter if this text is far out of sight. I assume this is a "feature"
> of the underlying Tk GUI.
>
> I.e. if you have done something like calculated the factorial of large
> numbers over and over again, or done prints in long loops etc, you can
> expect IDLE to be slow until you restart it.
>
> >From Python 2.3 under Windows I also feel that I've had problems with
> dead (or at least lost) python or pythonw processes floating around. If
> you are using Windows NT / 2000 / XP you can use the task manager to see
> these (under the processes tab) and kill them. Just don't kill your
> current IDLE editor window if you have unsaved work. :)
>
> There are other Python IDEs and editors than IDLE. The selection depends
> on your OS. For instance, on Windows there is PythonWin which comes with
> the win32all extensions, and is included in ActivePython. See
> http://www.python.org/cgi-bin/moinmoin/PythonEditors and
> http://www.python.org/cgi-bin/moinmoin/IntegratedDevelopmentEnvironments
> for plenty of other examples.
>
> You probably get the best performance if you run Python scripts from your
> command line. I often have a Command Prompt (cmd.exe) open in Windows and
> start my program from there after having saved in the editor. Restarting
> after a new editing cycle is just a matter of saving in the editor,
swapping
> to the command prompt with Alt-Tab and pressing Up-Arrow follows by Enter.
>
>
> > >>> ================================ RESTART
================================
>
> This is a feature! Previous versions of IDLE ran your script in the
> same process as the IDLE GUI, and this caused a lot of problems. For
> instance, it was impossible to run most Python GUI programs from
> inside IDLE, and modified modules used by your script wouldn't be
> reloaded as expected etc. Restart is your friend! :)
>
> > I only ran the module a few times before this problem started, but I
don't think the -----RESTART---- line was appearing at first, but I could be
wrong.
>
> If you start IDLE by right-clicking a file in the explorer, and
> choose "Edit with IDLE", you will get a single process version of
> IDLE, where the restart thing doesn't work. I don't know why they
> have done it like that.
>
> If you start IDLE from the Start menu, and open your programs from
> within IDLE, you will get the restart behaviour. It seems you have
> a real resource problem on your computer if it seems expensive to
> start a new process when you run a script, but check with the task
> manager to see if there are old python processes hanging around...
>
>
> -- 
> Magnus Lycka, Thinkware AB
> Alvans vag 99, SE-907 50 UMEA, SWEDEN
> phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
> http://www.thinkware.se/  mailto:magnus at thinkware.se
>
>
>
> ------------------------------
>
> Message: 2
> Date: Wed, 11 Feb 2004 10:13:56 -0800 (PST)
> From: Andrew Eidson <abeidson at sbcglobal.net>
> Subject: [Tutor] Pulling data from a DBaseIV file
> To: tutor at python.org
> Message-ID: <20040211181356.89318.qmail at web80105.mail.yahoo.com>
> Content-Type: text/plain; charset="us-ascii"
>
> Ok.. I have search the web and can not seem to find my answer.. I want to
pull data from a DBaseIV file and convert it to a tab delimited file.. I
have found PyxBase but it will not install for me.. is this functionality
built into 2.3.3 or is there another way of accessing a DBF file in python??
I found an old thead in the Tutor archive but the link that was presented
was dead..
>
> Thanks
> Andy
>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
http://mail.python.org/pipermail/tutor/attachments/20040211/c818f3a9/attachment-0001.html
>
> ------------------------------
>
> Message: 3
> Date: Wed, 11 Feb 2004 14:23:07 -0500
> From: Lloyd Kvam <pythontutor at venix.com>
> Subject: Re: [Tutor] Pulling data from a DBaseIV file
> To: Andrew Eidson <abeidson at sbcglobal.net>
> Cc: tutor at python.org
> Message-ID: <402A811B.5040504 at venix.com>
> Content-Type: text/plain; charset=us-ascii; format=flowed
>
> I needed to do something similar a couple of years ago.  I downloaded
> a module from (I think) Vaults of Parnassus.  It decoded the
> dBase header structure OK, but was clumsy to use.  I reworked it for
> my purposes.  I'll send you my reworked code (off-list).  You should be
able to
> turn it into something useful without too much grief.
>
> Andrew Eidson wrote:
>
> > Ok.. I have search the web and can not seem to find my answer.. I want
> > to pull data from a DBaseIV file and convert it to a tab delimited
> > file.. I have found PyxBase but it will not install for me.. is this
> > functionality built into 2.3.3 or is there another way of accessing a
> > DBF file in python?? I found an old thead in the Tutor archive but the
> > link that was presented was dead..
> >
> > Thanks
> > Andy
> >
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
> -- 
> Lloyd Kvam
> Venix Corp.
> 1 Court Street, Suite 378
> Lebanon, NH 03766-1358
>
> voice: 603-653-8139
> fax: 801-459-9582
>
>
>
>
> ------------------------------
>
> Message: 4
> Date: Wed, 11 Feb 2004 11:32:02 -0800
> From: Bob Gailer <bgailer at alum.rpi.edu>
> Subject: Re: [Tutor] Pulling data from a DBaseIV file
> To: Andrew Eidson <abeidson at sbcglobal.net>, tutor at python.org
> Message-ID: <6.0.0.22.0.20040211113154.036afc00 at mail.mric.net>
> Content-Type: text/plain; charset="us-ascii"; format=flowed
>
> At 10:13 AM 2/11/2004, Andrew Eidson wrote:
> >Ok.. I have search the web and can not seem to find my answer.. I want to
> >pull data from a DBaseIV file and convert it to a tab delimited file.. I
> >have found PyxBase but it will not install for me.. is this functionality
> >built into 2.3.3 or is there another way of accessing a DBF file in
> >python?? I found an old thead in the Tutor archive but the link that was
> >presented was dead..
>
> ODBC?
>
> >Thanks
> >Andy
> >
> >
> >_______________________________________________
> >Tutor maillist  -  Tutor at python.org
> >http://mail.python.org/mailman/listinfo/tutor
>
> Bob Gailer
> bgailer at alum.rpi.edu
> 303 442 2625 home
> 720 938 2625 cell
>
>
>
>
> ------------------------------
>
> Message: 5
> Date: Wed, 11 Feb 2004 11:33:36 -0800 (PST)
> From: Andrew Eidson <abeidson at sbcglobal.net>
> Subject: Re: [Tutor] Pulling data from a DBaseIV file
> To: tutor at python.org
> Message-ID: <20040211193336.73898.qmail at web80106.mail.yahoo.com>
> Content-Type: text/plain; charset=us-ascii
>
> Thanks.. I will take a look and see if I can get it to
> do what I want.. be ready for a flurry of questions
> though since I am still relatively new to programming
> as well as python.
>
>
>
> ------------------------------
>
> Message: 6
> Date: Wed, 11 Feb 2004 14:59:51 -0500
> From: Jeff Kowalczyk <jtk at yahoo.com>
> Subject: [Tutor] time arithmetic with 2.3 datetime module
> To: tutor at python.org
> Message-ID: <pan.2004.02.11.19.59.50.926090 at yahoo.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Embarrassing to ask, but I can't quite figure 'time differences' with the
> 2.3 datetime module. Every google link points to a copy of the docs,
> no tutorials on the new functionality. Every effort I make with timedelta
> or time arithmetic eventually goes awry with TypeError: unsupported type
> for timedelta seconds component: datetime.time
>
> I have a simple timecard input of strings:
>
> date, start, end = '20040206', '10:30', '17:45'
>
> After I parse out the date string:   y,m,d = d[:4],d[4:6],d[6:]
> I want to make two times from the 24h time strings, combining with the
> shared parsed date if necessary, and return the difference in floating
> point (e.g. 7.25). Can anyone suggest the most expedient way to do this?
> Thanks.
>
>
>
>
>
>
> ------------------------------
>
> Message: 7
> Date: Wed, 11 Feb 2004 12:09:12 -0800 (PST)
> From: Andrew Eidson <abeidson at sbcglobal.net>
> Subject: Re: [Tutor] Pulling data from a DBaseIV file
> To: Tutor at python.org
> Message-ID: <20040211200912.23283.qmail at web80105.mail.yahoo.com>
> Content-Type: text/plain; charset=us-ascii
>
> The ODBC information I find only pertains to SQL based
> systems.. I have not been able to find any information
> for a DbaseIV file..
>
>
>
> ------------------------------
>
> Message: 8
> Date: Wed, 11 Feb 2004 13:43:21 -0800
> From: Bob Gailer <bgailer at alum.rpi.edu>
> Subject: Re: {Spam?} Re: [Tutor] Pulling data from a DBaseIV file
> To: Andrew Eidson <abeidson at sbcglobal.net>, Tutor at python.org
> Message-ID: <6.0.0.22.0.20040211131711.01d51870 at mail.mric.net>
> Content-Type: text/plain; charset="us-ascii"; format=flowed
>
> At 12:09 PM 2/11/2004, Andrew Eidson wrote:
> >The ODBC information I find only pertains to SQL based
> >systems.. I have not been able to find any information
> >for a DbaseIV file..
>
> What operating system? If windows, you can set up an ODBC for dBase using
> the data sources applet. Let's say you call it "boreland".
>
> Then:
> import odbc
> conn = odbc.odbc('boreland')
> cursor = conn.cursor()
> cursor.execute('select * from table')
> rows = cursor.fetchall()
>
> Now you have a sequence of rows, each row being a sequence of columnvalues
>
> There is, as I recall, a CSV module that will create CSV files.
>
> Bob Gailer
> bgailer at alum.rpi.edu
> 303 442 2625 home
> 720 938 2625 cell
>
>
>
>
> ------------------------------
>
> Message: 9
> Date: Wed, 11 Feb 2004 17:25:18 -0500
> From: "Ron Alvarado" <rha207 at worldnet.att.net>
> Subject: [Tutor] readline() problem
> To: <tutor at python.org>
> Message-ID: <000501c3f0ed$eeb28c60$4a394b0c at computer>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Here's what I'm getting when I try readline(). What an I doing wrong?
>
> >>> data = open('bData.csv', 'r')
> >>> num = True
> >>> while num != "":
>  data = data.readline()
>  print data
>
>
> Part number Description Item Cost 1104 1105 1118
>
>
> Traceback (most recent call last):
>   File "<pyshell#7>", line 2, in -toplevel-
>     data = data.readline()
> AttributeError: 'str' object has no attribute 'readline'
> >>>
>
>
>
>
> ------------------------------
>
> Message: 10
> Date: Wed, 11 Feb 2004 17:28:50 -0500
> From: hcohen2 <hcohen2 at comcast.net>
> Subject: Re: [Tutor] readline() problem
> To: Ron Alvarado <rha207 at worldnet.att.net>
> Cc: tutor at python.org
> Message-ID: <402AACA2.8080901 at comcast.net>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Ron Alvarado wrote:
>
> >Here's what I'm getting when I try readline(). What an I doing wrong?
> >
> >
> >
> >>>>data = open('bData.csv', 'r')
> >>>>num = True
> >>>>while num != "":
> >>>>
> >>>>
> > data = data.readline()
> > print data
> >
> >
> When you openned the file, data was the file handle which you have
> confused it with a string value of the same name.  Since data types are
> dynamic in Python your file handle value is lost.
>
> try
>
> str_data = data.readline()
> print str_data
>
> both that line and the print should be to the right of the 'while ...'
>
> >
> >Part number Description Item Cost 1104 1105 1118
> >
> >
> >Traceback (most recent call last):
> >  File "<pyshell#7>", line 2, in -toplevel-
> >    data = data.readline()
> >AttributeError: 'str' object has no attribute 'readline'
> >
> >
> >
> >
> >_______________________________________________
> >Tutor maillist  -  Tutor at python.org
> >http://mail.python.org/mailman/listinfo/tutor
> >
> >
> >
>
>
>
>
>
> ------------------------------
>
> Message: 11
> Date: Wed, 11 Feb 2004 14:33:49 -0800 (PST)
> From: Marilyn Davis <marilyn at deliberate.com>
> Subject: Re: [Tutor] readline() problem
> To: tutor at python.org
> Message-ID: <Pine.LNX.4.44.0402111426250.11161-100000 at Kuna>
> Content-Type: TEXT/PLAIN; charset=US-ASCII
>
> On Wed, 11 Feb 2004, Ron Alvarado wrote:
>
> > Here's what I'm getting when I try readline(). What an I doing wrong?
> >
> > >>> data = open('bData.csv', 'r')
> > >>> num = True
> > >>> while num != "":
> >  data = data.readline()
> >  print data
>
> The first call to data.readline() will read the first line of the
> file, make a string of it, and then rename 'data' to be that
> string/line.  From then on, all is lost because you have lost your
> identifier that points to the file.  Next time around the loop, 'data'
> is that last line/string and it doesn't know anything about the file
> or 'readline'.
>
> The best solution is to rename the file:
>
> file = open('bData.csv', 'r')
> num = True
> while num != "":
>     data = file.readline()
>     print data
>
> However, this will cause an infinite loop because num never becomes
> "".  So you still have a problem to work out.
>
> Good luck!
>
> Marilyn Davis
>
>
>
> >
> >
> > Part number Description Item Cost 1104 1105 1118
> >
> >
> > Traceback (most recent call last):
> >   File "<pyshell#7>", line 2, in -toplevel-
> >     data = data.readline()
> > AttributeError: 'str' object has no attribute 'readline'
> > >>>
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
> -- 
>
>
>
>
>
> ------------------------------
>
> Message: 12
> Date: Wed, 11 Feb 2004 23:24:03 +0100
> From: sigurd at 12move.de (Karl Pfl?sterer )
> Subject: Re: [Tutor] time arithmetic with 2.3 datetime module
> To: tutor at python.org
> Message-ID: <m3hdxxi88a.fsf at hamster.pflaesterer.de>
> Content-Type: text/plain; charset=us-ascii
>
> On 11 Feb 2004, Jeff Kowalczyk <- jtk at yahoo.com wrote:
>
> > no tutorials on the new functionality. Every effort I make with
timedelta
> > or time arithmetic eventually goes awry with TypeError: unsupported type
> > for timedelta seconds component: datetime.time
>
> > I have a simple timecard input of strings:
>
> > date, start, end = '20040206', '10:30', '17:45'
>
> > After I parse out the date string:   y,m,d = d[:4],d[4:6],d[6:]
> > I want to make two times from the 24h time strings, combining with the
> > shared parsed date if necessary, and return the difference in floating
> > point (e.g. 7.25). Can anyone suggest the most expedient way to do this?
>
>
> You could do it like that
> >>> import datetime as dt
> >>> date, start, end = '20040206', '10:30', '17:45'
> >>> d, start, end = '20040206', '10:30', '17:45'
> >>> y,m,d = d[:4],d[4:6],d[6:]
> >>> starthr, startmin = map(int,start.split(':'))
> >>> endhr, endmin = map(int,end.split(':'))
> >>> d1 = dt.datetime(int(y), int(m), int(d), starthr, startmin)
> >>> d2 = dt.datetime(int(y), int(m), int(d), endhr, endmin)
> >>> delta = d2 - d1
> >>> delta
> datetime.timedelta(0, 26100)
> >>> delta.seconds
> 26100
> >>>
>
> Now you just need a function to convert the seconds in a format you
> like.
> E.g. like that:
>
> >>> def secs_to_float (s):
> ...     divs = [60, 60, 24, 365]
> ...     res = []
> ...     for div in divs:
> ...         s, r = divmod(s, div)
> ...         res.append(r)
> ...     res[1] = res[1] / 60.0
> ...     res[0] = res[0] / 3600.0
> ...     res.reverse()
> ...     return  res
> ...
> >>> secs_to_float(delta.seconds)
> [0, 7, 0.25, 0.0]
> >>>
>
> Above should be combined in one ore two functions.
>
>
>    Karl
> -- 
> Please do *not* send copies of replies to me.
> I read the list
>
>
>
>
> ------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest, Vol 7, Issue 30
> ************************************
>




More information about the Tutor mailing list