[Tutor] Leading zero for hex numbers

2004-12-15 Thread Tony Cappellini

I'm trying to get Python to automatically print a leading 0 for hex
numbers, but it only
seems to work for for decimal numbers.

print "0x%0X" % 12345

displays
0x3039

instead of 0x03039


The Python docs state
The conversion will be zero padded for numeric values, when a 0 is used as
a flag between the % and the conversion type.

Is this expected Python behaviour, or a mistake?

Sure, I can add some code to calculate the length of the current string to
decide if a leading 0 is needed., but if I don't have to, I'd rather not.


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Installation problem: Python 2.6.6 (32-Bit) on Windows 7 (32-Bit)

2010-08-31 Thread Tony Cappellini
Has anyone else had problems running the msi for Python 2.6.6 on Windows 7?

If I don't check "Compile .py to byte code", the installer completes
without error.
Checking "Compile .py to byte code" causes the following to be displayed

"There is a problem with the windows installer package. A program run
as part of setup did not complete as expected"

1. Yes I have plenty of disk space.
2. Yes I have admin privileges
3. Yes, the MD5 checksum of the downloaded installer matches the MD5
checksum on python.org
4. Run As Adminsitrator is not available when I Shift-Right Click
(probably because my user already has admin privileges)

I'm also having a similar issue with the PythonWin32 extensions
installer on the same machine.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] String formatting hex numbers

2009-05-30 Thread Tony Cappellini
I was looking at a this code which uses this code to dsiplay some hex numbers

 sys.stdout.write( "\r%-8s ... 0x%08X->0x%08X " % ( descr,
long(startAddr), long(endAddr) )

The hex values are in this range
0x1BFFF400 to 1BFFF000

Why are these displayed with a leading negative sign (between the 0x
and the actual number)- as seen below?

0x-1BFFF400 to 0x-1BFFF000


Thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] When max() doesn't work as expected

2009-12-03 Thread Tony Cappellini
I have a list of 2300 strings.

When I call max() on the list, it returned an item with 37 characters. I am
only passing 1 argument to max().
I know for a fact that the largest item has 57 characters, and when I called
mylist.index('my_57_character_string') the index was found.

Printing len(mylist[index]) does indeed return 57 characters.

What are the assumptions when calling max on a list of strings?
Does the list need to be sorted? In my case, the list is sorted.

Does max have any undocumented limitations I'm not aware of?

2.1 Built-in Functions  *max*( iterable[, args...][key]) With a single
argument iterable, return the largest item of a non-empty iterable (such as
a string, tuple or list). With more than one argument, return the largest of
the arguments.

The optional key argument specifies a one-argument ordering function like
that used for list.sort(). The key argument, if supplied, must be in keyword
form (for example, "max(a,b,c,key=func)"). Changed in version 2.5: Added
support for the optional key argument.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Iterating over multiple lists- options

2005-02-07 Thread Tony Cappellini

I'm trying to generate an HTML table, from multiple lists.
There are 4 lists total, each of which *may* have a different length from 
the other lists.
Each list has been stored in a master dictionary.

North=[Bill, Bob, Sue, Mary]
South=['Tim', ''Tom', 'Jim', 'John', 'Carl', 'Evan', 'Rich']
etc
d1={'North':North, 'South':South, 'East':East, 'West':West]
I want to iterate over all the lists a the same time, so I can populate an 
html table.
This is approximately what the HTML table should look like, but the lists 
can be in any order, top to bottom, and left to right.

South  North East West
Tim  BillMay  Ellen
Tom Bob   Mick
Jim  Sue   Ron
JohnMary  Keith
Carl  Joey
Evan
Rich
Looking through my books on Python I've found examples for zip() and map() 
both of which have serious shortcomings
That being, both of these functions can truncate the data, depending on 
certain conditions

When iterating over multiple lists, it is fine if the mechanism returns an 
empty string , or None for a non-existing list item.
I just wont display anything in the HTML table for missing items.
I know how to create the HTML table, statically. The problem is being able 
to fill the table in one pass (preferably), which means my program would 
need to iterate over
more than one list at the same time.

Even using the range to generate an index has different effects, depending 
on the order in which the lists are referenced in the for loop.

Are there any other options available for iterating over multiple lists ?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating over multiple lists- options

2005-02-07 Thread Tony Cappellini

> Out of curiosity, if it's not possible to run zip() directly on the lists
> that you have, can you bend the lists so that zip() will fit?
It is possible, however zip() truncates the longer list, based on the size
of the smaller list, so it's just not feasible in my case.

> Here's a quick function that should force a certain length on an iterator:
>
> ###
> def ipad(iterable, length, sentinel=None):
> """Returns a new iterator whose elements are taken from iterator.  If
> there are fewer elements than 'length', we pad the rest with
> sentinels.
>
> Assumptions: len(iterator) <= length.  The result from ipad never
> truncates the elements out of i, so the iterator always goes through
> all the elements in iterable.
> """
> i = 0
> for thing in iterable:
> yield thing
> i = i + 1
> while i < length:
> yield sentinel
> i = i + 1
> ###
>
>
> For example:
>
> ###
> >>> names = ['knuth', 'mcconnell', 'bentley', 'witten']
> >>> for n in ipad(names, 7):
> ... print n
> ...
> knuth
> mcconnell
> bentley
> witten
> None
> None
> None
> >>>
> >>>
> >>> for n in ipad(names, 2):
> ... print n
> ...
> knuth
> mcconnell
> bentley
> witten
> ###
>
>
> So we could use something like ipad() to bring all the lists to the same
> length, and that should make it suitable for zip().
>
>
> Hope this helps!
>
>

I see- yes it does. And since it's my first use of generators, without
really having to understand them, I'm more inclined to use this approach
:-)
I will just pad the short lists with the lenght of the longest list.
However, this brings up a question about map() ing over lists of different
lengths (which is what I started to use), but I'll post that in a
different message.

BTW, is your def ipad() function the 20gb, 40gb, or 60gb model ? :-)

Thanks


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating over multiple lists- options

2005-02-07 Thread Tony Cappellini

LOL

> Here's one, just for your amusement:
>
> But getting back on topic: I like Kent's solution with map() much better
> than my own.  I had completely forgotten that map() had a special case
> that applies directly to what you're trying to do.

I havne't seen Kent's reply yet- will have to look when I get home from
work.
But I 've found some inconsistnacies with map, depending on which order
the args were passed in.
If the shorter list was passed to map first, as in map(shortlist,
longerlist), it behaved one way.

If I reversed the order of the args, as in map(longerlist, shortlist),
map() behaved slighlty different. Almost like what zip() did.

Perhaps Kent's suggestion addresses this. I will see later.

Thanks!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating over multiple lists- options

2005-02-07 Thread Tony Cappellini
map(None, North, South, East West) does exactly what you want:
  >>> North=['Bill', 'Bob', 'Sue', 'Mary']
  >>> South=['Tim', 'Tom', 'Jim', 'John', 'Carl', 'Evan', 'Rich']
  >>> map(None, North, South)
[('Bill', 'Tim'), ('Bob', 'Tom'), ('Sue', 'Jim'), ('Mary', 'John'), (None, 
'Carl'), (None, 'Evan'),
(None, 'Rich')]

> That being, both of these functions can truncate the data, depending on
> certain conditions
>>I don't think that is true for map(); what conditions are you thinking of?
Well, I've tried duplicating what I was seeing last night when I posted the 
message, and it's not happening the same now.
Maybe I was up too later working on this problem...

What I *thought* I was seeing was map() would return a list of a certain 
length when I called it like this map(None, North, South)
and returned a list of a different length when I called it like this 
map(None, South, North)

However, trying that now basically returns the a list that appears to be 
the same length, for both calls.

I think this will work after all. I'll add it to my program .
Thanks for your quick replies
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Reading/writing Wave files

2005-02-16 Thread Tony Cappellini

After looking at the Python docs for the wave module, I'm a bit puzzled as 
to how to use it.

Does anyone have an example I can browse?
If I write to a wave file, is the data I write actually audible, if I use 
Winamp or some other wave player, or is it more complicated than that?
Is the data I write actually part of the content of the wave file, or do I 
have to manually handle the file structure of the wave file too (the part 
that is unique to wave files, that is)?

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Looking for a Pythonic way to pass variable number of lists to zip()

2005-03-21 Thread Tony Cappellini

I have a program which currently passes 6 lists as arguments to zip(), but 
this could easily change to a larger number of arguments.
Would someone suggest a way to pass a variable number of lists to zip() ?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 40, Issue 55

2007-06-24 Thread Tony Cappellini
Take a look at pyHook

>1. Re: Catch event's on my computer (Alan Gauld)
> From: "Alan Gauld" <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] Catch event's on my computer
> To: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> reply-type=original
>
> "Flaper87" <[EMAIL PROTECTED]> wrote
>
> > I mean, i need to catch every movement of the pointer, what its
> > position is
> > everything. I've read that i can do that using my native system API,
> > and
> > also pygame.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] os.rename anomaly in Python 2.3 on Windows XP

2007-10-08 Thread Tony Cappellini
Using Windows XP, SP2 and Python 2.3

I've written a script which walks through a bunch of directories and
replaces characters which are typically illegals as filenames, with an
'_' character.

The directories are part of a package of software which is released by
a group of people from Japan, and as such, they use their own
character set (probably Kanji). However, most of the time, there are
only 1 or 2 directories with unknown or illegal characters, as
determined by
my system (which does not use the Kanji characters).

When my script encounters a directory with the unwanted characters,
it's easy to detect them and filter them out. The next step is to
rename the file to get rid of the problem characters.

However, recently when I called os.rename(oldname, newname) an OS
exception was thrown with "Illegal filename". I was able to narrow it
down to oldname being the cause of the problem.
Some of the characters showed up as ? in the Python strings.

Oddly enough, os.rename() cannot perform the renaming of the
directories, but I can do this manually in File Explorer or even in a
CMD console using "rename"

So what is os.renaming() actually calling on a Windows system, that
won't allow me to rename dirs with illegal characters?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] os.rename anomaly in Python 2.3 on Windows XP

2007-10-09 Thread Tony Cappellini
Thanks.

Unfortunately,os.listdir() returns the same string as glob.glob, for
the problem file I mentioned.
When I pass that string to os.rename()

OSError: [Errno 22] Invalid argument

> Sounds like it has something to do with Unicode.
> Your filenames aren't being interpreted correctly.  Perhaps os.listdir
> is giving you the UTF-8 versions
> rather than the Unicode versions of the filenames?
> -Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Wrong version of Python being executed

2007-11-10 Thread Tony Cappellini
I've got Python 2.3, 2.4 and 2.5 installed on a Windows XP machine..

I currently have Python 2.5 in my path, and there are no other
versions of Python in the path.

I'm trying to run a program which expects Python 2.4 or later to be
installed, because there is a call to logging.BasicConfig(arg1, arg2)
which is passed two arguments

In Python 2.3, logging.BasicConfig() did not take any arguments.

When I run this python script, the following exception is thrown,
implying that it is being executed with Python 2.3
So I've added this print statement to the main function, which shows
the logging module is being imported from the Python 2.3 directory

print"\nlogging.__file__ = %s" % logging.__file__

logging.__file__ = C:\Python23\lib\logging\__init__.pyc



Traceback (most recent call last):
  File "c:\Project\myscript.py", line 584, in
?
main(sys.argv)
  File "c:\Project\myscript.py", line 518, in
main
logging.basicConfig(level=config.verbosity,format='%(message)s')
TypeError: basicConfig() takes no arguments (2 given)


The really odd thing is when I bring up the python interpreter at the
same command prompt where i ran the script above,
Python 2.5 is invoked, as seen by


Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version
'2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)]'


How is it that running a script invokes Python 2.3, but running the
interpreter without the script invoked Python 2.5?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-10 Thread Tony Cappellini
Thanks for replying Kent.
This is quite a strange mystery.

> A couple of possibilities...
> Is there a #! line at the start of the script that specifies Python 2.3
> (I'm not sure if those work in windows though...)
No- The shebang line is for non-Windows systems (Unix variants)

> How do you run the script? If you double-click it, perhaps the file
> association with .py files is to Python 2.3?
I run the script by typing python script.py

> Conceivably the Python 2.5 module path is incorrect and imports the
> wrong module. What happens if you import logging from the interpreter
> prompt and print its file?

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.__file__
'C:\\PYTHON25\\lib\\logging\\__init__.pyc'


What do you get if you print sys.path from
> the interpreter?

>>> import sys
>>> sys.path
['', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\PYTHON25\\DLLs',
'C:\\PYTHON25\\lib', 'C:\\PYTHON25\\lib\\plat-win', 'C
:\\PYTHON25\\lib\\lib-tk', 'C:\\PYTHON25',
'C:\\PYTHON25\\lib\\site-packages',
'C:\\PYTHON25\\lib\\site-packages\\win32'
, 'C:\\PYTHON25\\lib\\site-packages\\win32\\lib',
'C:\\PYTHON25\\lib\\site-packages\\Pythonwin', 'C:\\PYTHON25\\lib\\sit
e-packages\\wx-2.8-msw-ansi']
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-10 Thread Tony Cappellini
>>What do you get if you print sys.path from
> the interpreter?

I've printed out sys.path from inside the script as well,
and all references to Python25 are replaced with Python23


FWIW- This isn't a problem unique to this script.
I've just printed out sys.path from another script in another
directory, and Python2.3 is referenced.
So, it's a system wide issue- but I still don't know how or why it's happening.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-11 Thread Tony Cappellini
Martin Walsh mwalsh at groktech.org
Sun Nov 11 06:13:10 CET 2007

>>That is odd.

>>Try using the full path to python, just to be sure: c:\python25\python
>>script.py -- do you get the same behavior?
This works just fine- I would expect it to.

>>Also, if you haven't already, you can run python with the -E and/or -S
>>flags (ex. 'c:\python25\python -E -S script.py'). The -E flag will cause
>>the PYTHONPATH and PYTHONHOME environment variables to be ignored. And

This also works just fine. I've tried both switches independently, and
the scrip runs normally when I use either and both at the same time.
If I don't use them, then Python2.3 is being invoked somehow.

However, when I type set PYTHONPATH and
set PYTHONHOME

at the cmd prompt

SET PYTHONPATH
Environment variable PYTHONPATH not defined

SET PYTHONHOME
Environment variable PYTHONHOME not defined

Very strange indeed. It's starting to remind me of an episode from The
Twilight Zone ;-)

Is ti possible that my registry is corrupted?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2007-11-11 Thread Tony Cappellini
> Message: 4
> Date: Mon, 12 Nov 2007 00:16:35 -
> From: "Alan Gauld" <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] Wrong version of Python being executed
> To: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> reply-type=original
>

> This is very important. If you just type python at the Run
> dialog it uses a different algorithm to find the exe than if
> you type python at a DOS prompt inside a CMD window.

I never type anything in the Run dialog other than Regedit, or CMD.
I dont want that to sound defensive, but usually when I need a CMD
prompt, I'm need to be there for a long time, and that's why I open
it.
It never even occurred to me to type Python at the Run prompt.

Most of the time, I open a cmd prompt IN the directory where I want to
run a script, by using "Command Prompt Here", from Microsoft.
(why isn't this built into the OS after all this time ??)

But while troubleshooting this problem, I've not been using it, and
have been CD'ing down to where my sources are.

> Its the second algorithm that is used if you type
> python foo.py at a cmd prompt but the first that
> is used if you double click foo.py within explorer
I typically dont double click my scripts, unless they are guis, or exes'

> That *shouldn't* make any difference...but you can never be 100% sure!

I think a this point, I'll just re-install 2.3 and 2.5 to see if that
fixes it, with a reboot in-between.
I dont know what else to do.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-11 Thread Tony Cappellini
Message: 2
Date: Sun, 11 Nov 2007 16:57:01 -0600
From: Martin Walsh <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Wrong version of Python being executed
To: Tutor Python 
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1


>>My initial thought based on your description was that python2.5 is
being invoked with PYTHON* env
>>vars from a previous install, or some site module weirdness.

Not sure how the "previous install" surfaced, but I installed all
python installations and packages on my computer.

I have to switch between 2.3 and 2.5, so to make it easy, I use an
environment variable called CURRENT_PYTHON.
(someone on this list or the wxPython list told me I should NOT use
PYTHONPATH and modify it the way I am using CURRENT_PYTHON)

CURRENT_PYTHON=C:\PYTHON2X
path=%CURRENT_PYTHON%
(The existing path isn't shown, only for brevity)

Note, these are entered in Ctrl Panel, System environment variables,
NOT at the command line.


>>But, the fact that running python.exe with it's full path corrects the issue,
>>seems to indicate a problem with your PATH, rather than any python
Yes, my conclusion also, but what is wrong with the path?
I've posted the contents of PATH in the original email or one of the
subsequent ones.

>>Would the following be an accurate description of the behavior?

>>assuming:
>>- you run inside a fresh 'cmd' console each time (typing 'cmd' at the
>>run dialog, or similar), to be sure there is no app environment kruft

correct-

>>- the current working directory doesn't contain any programs, scripts or
>>possibly links that could interfere (preferably an empty path)

Not that I can see

>>- you don't have any PYTHON* environment vars set (including PYTHONSTARTUP)

No- see for yourself. No python anything variables.
C:\Documents and Settings\z30032as>set python
Environment variable python not defined

>>you observe:
>>- when you type 'python' (only 'python') at the prompt, you get
>>python2.5 interactively

Correct

>>- when you use the form 'python script.py', the script is run with
>>python2.3 (can you verify with sys.version?) with sys.path appropriate
>>for 2.3

Correct

>>- when you use the form 'c:\python25\python.exe script.py', the script
>>is executed with python2.5 and you have the correct sys.path (for 2.5)
Correct

>>I wouldn't think so, but I suppose it is possible. I believe all the
>>pertinent registry keys are store under
>>"HKLM\Software\Python\Pythoncore\", so you could have a look.

Already did. There IS a PYTHONPATH entry for each of the 3 versions of
Python I have installed.
They are all identical, with the exception of the last 2 digits for
the Python version.
This looks ok to me. No other rogue entries of PYTHONPATH were found
in the registry.

>>BTW, are you using an alternate distribution of python (ex.
>>ActiveState), or the standard python.org version?

No. I always use the regular Python.Org distributions. I never
understood what was so special about ActiveState anyway.
I;d rather have full control of my installs, and all the packages.
Although, at this point, I'm not in control over what is happening
with my path ;-)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-12 Thread Tony Cappellini
Date: Mon, 12 Nov 2007 09:14:05 -
From: "Alan Gauld" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Wrong version of Python being executed
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
   reply-type=original



>>Umm, have you rebooted? Probably an obvious step but I don't
many times
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wrong version of Python being executed

2007-11-19 Thread Tony Cappellini
I've found something interesting regarding this issue.

I went to Windows Explorer, Tools,Folder Options, File Types and
noticed that there are two different icons associated with .PY files.
The Icon for Python 2.5 is easy to recognize as compared with the icon
for Python 2.3.

So I've changed the association from the 2.3 icon to the 2.5 icon, and
now I can run my script from the command line as follows

python script.py, and the correct version of Python is invoked.

This is very disturbing because it means the path or other env vars
have no control (or very little) as to which version of Python is
invoked.


How do other people deal with having multiple versions of Python on
their system, and not run into this issue??



On Nov 10, 2007 6:16 PM, Kent Johnson <[EMAIL PROTECTED]> wrote:
>
> Tony Cappellini wrote:
> > When I run this python script, the following exception is thrown,
> > implying that it is being executed with Python 2.3
> > So I've added this print statement to the main function, which shows
> > the logging module is being imported from the Python 2.3 directory
> >
> > print"\nlogging.__file__ = %s" % logging.__file__
> >
> > logging.__file__ = C:\Python23\lib\logging\__init__.pyc
> >
> >
> >
> > Traceback (most recent call last):
> >   File "c:\Project\myscript.py", line 584, in
> > ?
> > main(sys.argv)
> >   File "c:\Project\myscript.py", line 518, in
> > main
> > logging.basicConfig(level=config.verbosity,format='%(message)s')
> > TypeError: basicConfig() takes no arguments (2 given)
> >
> >
> > The really odd thing is when I bring up the python interpreter at the
> > same command prompt where i ran the script above,
> > Python 2.5 is invoked, as seen by
> >
> >
> > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
> > (Intel)] on win32
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> import sys
> >>>> sys.version
> > '2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)]'
> >
> >
> > How is it that running a script invokes Python 2.3, but running the
> > interpreter without the script invoked Python 2.5?
>
> A couple of possibilities...
> Is there a #! line at the start of the script that specifies Python 2.3
> (I'm not sure if those work in windows though...)
>
> How do you run the script? If you double-click it, perhaps the file
> association with .py files is to Python 2.3?
>
> Conceivably the Python 2.5 module path is incorrect and imports the
> wrong module. What happens if you import logging from the interpreter
> prompt and print its file? What do you get if you print sys.path from
> the interpreter?
>
> HTH,
> Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 45, Issue 58

2007-11-20 Thread Tony Cappellini
- Forwarded Message 
From: Doug Glenn <[EMAIL PROTECTED]>
To: Alan Gauld <[EMAIL PROTECTED]>
Sent: Tuesday, 20 November, 2007 4:08:12 AM
Subject: Re: [Tutor] Wrong version of Python being executed

>>It is a bit odd since normally Pythons installation mechinism only
>>does it for the PY file on install.  You may have clicked on it
>>sometime in the past and then selected "run with" and it remembered
>>the association.

I'm pretty sure every time I've installed Python that the associations
get changed. However, since the executable is the same name for all
versions of python (but the path is different), this doesn't help when
you want to use one version instead of another.

File associations are checked first, then it will check the path if
there is no association.  This is default windows behavior.

>>Glad you got it sussed out!
I know the reason of the strange behaviour, but not a solution at this point.
I have a library which only works for Python2.3. When I start working
on that project again, I 'll have to re-associate .py with 2.3.
This isn't convenient (and it's likely I will have forgotten all about
this by then) :-)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Choice of GUI builders

2008-01-03 Thread Tony Cappellini
Message: 1
Date: Thu, 3 Jan 2008 08:11:05 -
From: "Alan Gauld" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Choice of GUI builders
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
   reply-type=original


>>OK, wxPython is a fine toolkt. Just be aware that it does not have a GUI
>>builder per se, you have to write the GUI as source code or use a
>>third party GUI builder.


The Add-Ons & Demos for wxPython come with Xrced, which is a GUI
builder for wx, but is not the GUI builder we all think of (VB,
Delphi, C++ Builder, etc)
There are a handlfull of GUI builders for wx, all with varying degrees
of pain & pleasure.
wxDesigner,wxFormBuilder, BoaConstructor, Pythoncard are all builders
for wx, but not all support Python code generation.

I agree with Marc Tompkins" <[EMAIL PROTECTED]> comments and
like wx more than other GUI frameworks.
It's a shame that someone with adequate resources doesn't come up with
a nice commercial WYSIWIG builder for wx, in the same light as Visual
Basic, Delphi, or C++ Builder, (but with Python code generation &
event handler management.)

BTW- There is a list dedicated for wxPython users & development that
is extremely help for questions related to wx.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 47, Issue 8

2008-01-03 Thread Tony Cappellini
Message: 1
Date: Thu, 3 Jan 2008 10:06:01 -0200
From: Tiago Saboga <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Choice of GUI builders
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=us-ascii

>>But since 2005, according to wikipedia, the Qt Windows is also
>>licensed under the GPL. Am I missing something?
There is a GPL version of QT, I believe it came into being for QT 3.x

>>t's why I finally started using Qt. In fact I do not really like
>>WYSIWYG designers -
There is a free designer for QT/PyQT as well. I started with qt/Pyqt
but have moved to wx since then.

Putting  widgets into sizers is easy with the designers. Not knowing
how to fix your code when the widgets don't appear as you want them is
a problem. I've never seen any docs written to help overcome this for
any framework.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 47, Issue 8

2008-01-03 Thread Tony Cappellini
The point I was trying to make that didn't come across is:
Until one has enough experience to hand code the GUIs, the designers
are helpful and a good place to begin.

The problem with widgets not appearing where they should is not a
problem with the GUI designer, but the lack experience with the
particular toolkit by the programmer.


On Jan 3, 2008 1:00 PM, Marc Tompkins <[EMAIL PROTECTED]> wrote:
> On Jan 3, 2008 10:31 AM, Tony Cappellini <[EMAIL PROTECTED]> wrote:

> It's like OCR and speech-to-text.  At some point it becomes easier to do it
> by hand than to straighten out the dog's breakfast that the "labor-saving"
> tool made for you.
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] shutils.copytree

2008-01-10 Thread Tony Cappellini
I'm using shutils for the first time, and I've un into a problem.
The docs for copytree are pretty sparse and don't mention any problem situations

Under WinXP, I'm trying to copy a directory tree to a USB device using
copytree, but copytree doesn't like a drive letter as a destination.

copytree('C:\\testdir', 'g:\\')

OsError: Permission denied was displayed

However, when I changed the call to copytree('C:\\testdir', 'g:\\junk')

copytree worked.

Why is the root directory '\\' not a valid destination?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] shutils.copytree

2008-01-11 Thread Tony Cappellini
> The source for copytree says, "The destination directory must not
> already exist." I suppose that is why you have a problem but I don't
> know the specific cause. Did you get a traceback?
>
> The source also says, "Consider this example code rather than the
> ultimate tool" so maybe you should just copy it and make a version that
> does what you want. See shutil.py in your Python lib directory.

Yes, I did read that and was shocked. Is everything in python that
iffy? I believe there was a traceback, I'll have to look again when I
am back at work tomorrow.
The problem with that concept of "modifying the distribution as you
go" is that those changes must be moved to every system where your
program will run, and whenever python is updated, you have to remember
to save the changes before uninstalling the current version. The
shutils in the new python dist may not be compatible with your old
changes and may require more work. Bad idea. How did that ever get
approved to be in the standard distribution?

>>Also -- vaguely -- have a look at my notes on file copying
>>under windows to consider alternatives:
>>http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html

I had started doing xcopy, but it became unreliable but I don't know
why yet, so I decided to try shutil.
I am doing the file copies in a thread, but that shouldn't matter.
I will look at your other file copy suggestions.

Thansk for both replies


Message: 1
Date: Fri, 11 Jan 2008 09:02:49 +
From: Tim Golden <[EMAIL PROTECTED]>
Subject: Re: [Tutor] shutils.copytree
Cc: Tutor Python 
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hello and newbie question about "self"

2008-02-03 Thread Tony Cappellini
>>http://www.ibiblio.org/swaroopch/byteofpython/read/self.html
Is there a typo in the contents of this web page?

Should this statement

Note for C++/Java/C# Programmers

The self in Python is equivalent to the "self" pointer in C++ and the
this reference in Java and C#.


Actually be

Note for C++/Java/C# Programmers

The self in Python is equivalent to the "this" pointer in C++ and the
this reference in Java and C#.


(I substituted "this" for "self")
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to deal with a thread that doesn't terminate

2008-02-19 Thread Tony Cappellini
On Feb 19, 2008 2:02 PM, bob gailer <[EMAIL PROTECTED]> wrote:
> Tony Cappellini wrote:
> > When I executing a program external to the main program in a thread,
> > and that thread hangs, can the thread be terminated?
> >
> Please define "hangs".

> AFAIK that could mean waiting on an external event / signal /
> communication that never happens, or running in an "infinite loop". So
> which is it or is it something else?

Never happens.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to deal with a thread that doesn't terminate

2008-02-19 Thread Tony Cappellini
When I executing a program external to the main program in a thread,
and that thread hangs, can the thread be terminated?
How does one handle this situation?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to deal with a thread that doesn't terminate

2008-02-20 Thread Tony Cappellini
Thanks Michael.



On Feb 19, 2008 11:23 PM, Michael Langford <[EMAIL PROTECTED]> wrote:
> Instead of using a thread, you could see if you could use a second
> process. For instance, the following would work on windows (and is
> killable).
>
> import subprocess
> import win32api
>
> class SpawnController(object):
> def __init__(self,cmd):
> self.cmdline = cmd
>
> def start(self):
> self.process = subprocess.Popen([self.cmdline])
>
> def stop(self):
> win32api.TerminateProcess(int(self.process._handle), -1
>
>--michael
>
>
> On Feb 19, 2008 4:53 PM, Tony Cappellini <[EMAIL PROTECTED]> wrote:
> > When I executing a program external to the main program in a thread,
> > and that thread hangs, can the thread be terminated?
> > How does one handle this situation?
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
>
> --
> Michael Langford
> Phone: 404-386-0495
> Consulting: http://www.RowdyLabs.com
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Confused about embedding python in Html

2005-08-20 Thread Tony Cappellini


I want to use embedded python in an html page.
However, I dont want to force the user to have python installed for the 
page to work.
Is there any way to make the embedded python code be executed by the server?

I'm hoping ti use python as an alternative to vbscript and jaava


thanks


tony

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] simple Model-View-Controller example for QT/PyQT

2006-07-24 Thread Tony Cappellini
Does anyone here have a  example/demo using the MVC pattern, in a simple QT/pyQT program?thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unusual behavior in readline

2006-08-08 Thread Tony Cappellini
I don't understand why readline is producing such unusual behavior.I don't remember it working like this previously. The docs say it is supposed to read a line at a time.this functiondef ProcessFile(self, Inputfile, Outputfile=None):
    
    try:    fh=open(Inputfile,"r")    except IOError:    print"\nError ocurred opening %s for input\n" % Inputfile    else:    FixedEntry = []

    Entry = ""    for Entry in fh.readline():    print"Entry = %s" % Entry            
fh.close()is producing this resultEntry = AEntry = lEntry = iEntry = aEntry = sEntry = ,Entry = PEntry = hEntry = oEntry = nEntry = eWith this input file

Alias,PhoneJANE SMITH,12131234567Readline is supposed to read an entire line on each call, yet it is only reading one character.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Making a better main() : Critique request

2006-08-20 Thread Tony Cappellini
Some time ago, I had read an article on Guido's blog (I think) about ways to improve the main() functionin a Python script. There were many replies, and I thought I would try to implement some of these ideas.

I had found that in every python program I wrote I would 1. check the number of arguments as well as checking that each argument was valid. 2. Provide an option for the user to display how long the program took to run, for those programs which
    processed a lot of files. 3  If any input files were used, I would also check to make sure they existed.     Recently, I've implemented a browser dialogue from Jimmy Retzlaff's EasyDialogs to make it easy to locate 
    files outside of the current directory.4. If the argument validation failed, a Usage() function would be called to show all possible arguments5. Provide a "help" option  to display all the possible arguments.
I could see that I was writing enough lines of code that main() was getting cluttered, and not easy to see what was happening at a glance. Sure, I could move all of this outside of main(), but some function had to
initiate all of the processing. So, I've decided to put all of this processing into a class. I had thought about putting this class in a separate file, so the file containing main() would only have a few imports, one line to instantiate the class to validate the cmd line args, and one function call to actually "start" the meat of the program, if all input args were valid.
I didn't like the idea of having to start with 2 files for every program. So now the class definition for the input processing is in the main file, and this file is now full of code, but at least main() is short & sweet.
Since I'm just getting back into using Python again, I would appreciate some constructive comments on this processing, and if this version of "a better main()" is really better or not.


So Now I'm trying to use more exception handling in the validating of the input arguments, and have defined a few of my own exceptionclasses.However, I'm getting the cart before the horse, and can't see the forest through the trees.
I don't like the idea of defining classes within classes, but I'm havign a problem geting the ProgramStartup class tosee the ArgumentError exception class.Am Ion the right track to makign a better main by moving all the argument validation to a class, or should I levae it to discrete functions in the main file?
thanks# system importsfrom os import getcwdimport stringimport sysimport typesimport timeimport getoptfrom EasyDialogs import AskFileForOpenfrom os.path import existsfrom exceptions import Exception
# system imports# user-defined importsimport tcpyfrom tcpy import pausefrom tcpy import cls# user-defined imports#/# USER-DEFINED EXCEPTIONS
class UserExceptions(Exception):    def __init__(self, args=None):    self.args = argsclass ArgumentError(UserExceptions):    def __init__(self):    #UserExceptions.__init__(self, args)
    #self.args = args    pass    class ProgramExitError(UserExceptions):    def __init__(self, args):    UserExceptions.__init__(self, args)    self.args = args    
#/# CLASS DEFINITIONS#/class ProgramStartup(object):    "this class will handle all the details of checking/validating the program arguments"
        def __init__(self, ProgramArgs):    self.MinArgs = 1     self.MaxArgs = 2 #input filename    self.ShowTimer = False    self.StartTime = 0    self.EndTime = 0    
self.InputFilename = ""        self.ProgramName = ""    self.ProgramVersion = "0.1"    self.BAD_ARG = True    self.ArgsDict ={'-t':"Show program execution time",
    '-v':"Show program version number",    '-b':"Browse for input file",    '-f ':"File to be processed",
    '-h':"Show this help screen"    }    self.ValidArgs ='tvbf:'        try:    self.ValidateArgs(ProgramArgs)    except getopt.GetoptError
, ArgumentError:    self.Usage()    def Usage(self):        print"\nSyntax is: ",     print"%s " % ProgramName,    for key in self.ArgsDict.iterkeys():
    print"%s " % key,        print"\n\nWhere"    for key, item in self.ArgsDict.iteritems():    print"\n%s=%s" %(key, item)     print    
sys.exit()    def ShowExecTime(self):        if self.ShowTimer:    print"\nTotal time = %6.2f seconds" % (self.EndTime-self.StartTime)        return None
    def ShowTitle(self):        print"\n\n%s Version %s \n\n" %(self.ProgramName, self.ProgramVersion)    return None    def ValidateArgs(self, args):    global AskFileForOpen, getcwd, ArgumentError
        ArgValidationStatus = 0    self.InputFilename = Non

[Tutor] Fatal error after RE-installing Python 2.3.4

2006-09-22 Thread Tony Cappellini
I've just started a job which has a massive python2.3.4-centric tools installation and configuration.I know what you're going to say, but I can't upgrade and be the only one with a newer version. There are close to 30 engineers using this same tools configuration, and it has been working fine for a long time.
For now, we all have to live with the limitations and or bugs in 2.3.4.I'm running Windows XP, SP2, on a AMD 1.79Ghz MP 2200+.After editing/testing one of the python test scripts, I was about to check a small script change into cvs, when my mentor suggested running pychecker. When I did this, I saw a several pages full of warnings.
For me not knowing the code base well enough to know what to expect, He thought this was odd, took the file, ran pychecker on his system, and only sees 4-5 warnings.We have the same version of Python, that being 
2.3.4, the same version of pychecker which is 0.8.14.I had deleted and re-installed pychecker, and still saw the same warnings.I compared this to another machine, and again, I am the odd man out.I've deleted all the Python packages, pythonwin, and The core 
2.3.4 distribution, and re-installed everything from scratch.Now, When I launch Python from a cmd console, the following is reportedC:\Windows\system32\cmd.exe- pythonThe NTVDM CPU has encountered an illegal instruction.
Chose close to terminate the application.Oddly enough, when I run Python.exe from the Program Files menu, it launches just fine.The virus scanner doesn't find any known viruses, and I've also disabled the virus checker after un-installing-reinstalling Python the last time.
I've also tried downloading another copy of the installer.Does anyone have any ideas what is causing this and how to fix it? My job depends on me getting Python2.3.4 back to working order.thanks

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 31, Issue 66

2006-09-23 Thread Tony Cappellini
Message: 4Date: Sat, 23 Sep 2006 08:38:37 +0100From: "Alan Gauld" <
[EMAIL PROTECTED]>Subject: Re: [Tutor] Fatal error after RE-installing Python 2.3.4To: tutor@python.orgMessage-ID: <
[EMAIL PROTECTED]>Content-Type: text/plain; format=flowed; charset="iso-8859-1";reply-type=original>>Have you installed in the same place as everybody else? Are your PATH settings the same?
I assume you mean the default install dir. C:\Python23. YesWe have a detailed installation prodcedure. Everyone is supposed to use this.I have verified the path with another working system.
>>Otherwise I'm stumped and would tend to go for removing every reference to Python, including all registry >>entries.Doesn't the uninstall do this automatically? I selected the "Automatic" setting during the uninstall.
I had a working Python isntallation for the last 2 weeks. I was able to run scripts just fine.Only after uninstalling and resinstalling did this problem show up.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fatal error after RE-installing Python 2.3.4

2006-09-24 Thread Tony Cappellini
Message: 1Date: Sat, 23 Sep 2006 08:25:13 -0400From: Kent Johnson <[EMAIL PROTECTED]>Subject: Re: [Tutor] Fatal error after RE-installing Python 
2.3.4Cc: tutor@python.orgMessage-ID: <
[EMAIL PROTECTED]>Content-Type: text/plain; charset=ISO-8859-1; format=flowed>>Were the extra warnings legitimate (i.e., the code really does have theHard to say, since my system was the only one that exhibits this problem.
But pychecker isn't really the concern, getting Python running is the main issue.>>Were the warnings all the same or just a few types? Many were the same- function/method not found. Bu tthis is ok, since many of the functions are assigned at runtime.
>> Maybe everyone else has pychecker configured to ignore those warnings - pychecker allows you to create a >>.pycheckrc file to configure it.My system doesn't have this, neither did two other systems where I ran pychecker on the same file.
This was the first thing I looked for.>>don't like to blame the hardware but this is pretty strange. Is it possible you have a hardware problem? >>It might be worth running a memoryDoubtful, because I have been running python for the last 2 weeks. This only started happening on Friday, after I re-installed python & pythonwin.
Thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] What not to put in __init__()

2006-10-03 Thread Tony Cappellini
I've just inherited a lot of python code to maintain.The __init__ functions in many of the classes are very long- some over 100 lines.I like to keep functions/methods short & readable at a glance, if possible.
1. Is it good methodology to move some code from _init__ to it's own method within the class?    For example there are many for loops with several levles of nested if statements within them.I'd like to move each of these for/if chunks to distinct methods, so to simplify the look of __init__, without modifying how it works.
thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Trying to understand sys.getrefcount()

2006-10-12 Thread Tony Cappellini
I'm using Python 2.3.4After reading this in the docs


getrefcount(
object)
Return the reference count of the object. The count returned is 
generally one higher than you might expect, because it includes the (temporary) 
reference as an argument to getrefcount().I decided to try some experiments class junk(object):...     pass... >>> sys.getrefcount(junk)5>>> j1=junk()
>>> sys.getrefcount(junk)6sys.getrefcount(j1)2I understand why j1 is 1 higher than I expect, based on the docs, but why does getrefcount(junk) return 5 before any instances of class junk are made?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what is PIL..???

2006-10-21 Thread Tony Cappellini
Also checkout GnuPlot http://www.gnuplot.info/and the Python bindings for ithttp://gnuplot-py.sourceforge.net/
Date: Sat, 21 Oct 2006 14:07:12 +0100From: "Asrarahmed Kadri" <[EMAIL PROTECTED]>
Subject: [Tutor] what is PIL..???To: pythontutor Message-ID:        <
[EMAIL PROTECTED]>Content-Type: text/plain; charset="iso-8859-1"Folks,Continuing my journey into "Tkinter world"...May I ask someone to tell what PIL is and how can it be helpful in drawing
2-dimensional graphs...Thanks..
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running multiple version of Python on 1 windows

2006-10-31 Thread Tony Cappellini
>From Kent >>You don't say what OS you are running but under Windows it is trivial to>>have multiple versions of Python installed, I have 2.3, 2.4 and 2.5.>>They are each in their own directories, all in the system path. I have
>>aliases called py23, py24 and py25 that let me launch the version I>>want. I'm pretty sure you can do something similar with other OSes.If you want script abc.py to run with python 2.3, and script 
xyz.py to run with 2.5, how can you control this form the command line?python abc.pyvspython xyz.py?One task I'm faced with is evaluating the benefits of migrating a huge framework from 
2.3 to 2.4?I'd rather use two machines for this rather than install 2.4 on my 2.3 machine.If I need to make any changes in the scripts to work on 2.4, I don't want that interfering with a fully-working 2.3 environment.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Print Screen

2006-11-03 Thread Tony Cappellini
Date: Thu, 02 Nov 2006 20:09:59 -0500From: Bill Burns <[EMAIL PROTECTED]>Subject: Re: [Tutor] Print Screen
To: Chris Hengge <[EMAIL PROTECTED]>Cc: pythontutor <
tutor@python.org>Message-ID: <[EMAIL PROTECTED]>Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>>pressed, try pyHook. Note: pyHook only works on Windows!To elaborate, pyHook only works on Win2k and later.I had no success with Windows 98
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using CVS through Python

2006-11-11 Thread Tony Cappellini
I need to do some automated checkouts of CVS projects from Python scripts, and want ot be able to handle success and failure conditions.While sending the command lines to cvs isn't a problem, I could use some suggestions for how to check the cvs responses.
Parsing the text returned from CVS isn't  a good idea, since I don't know all of the possible combinations of strings indicating sucess of failure.I wasn't able to find any wrappers for Python by googling.
Suggestions pelase..
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] moving from pack to grid in tkinter

2006-11-26 Thread Tony Cappellini

I've got a main window which is 640 * 400.
 self.root.geometry("600x400")

self.label.pack(side=BOTTOM, fill=X)
This line would put the label at the bottom of the window, and extend to
both left and right edges of the window.

I want to change to grid geometry because I have several more widgets to put
in the main window.
self.label.grid(row=5, column=2, column=0)

This put the label at row 5, in the center of the window, but the label
didn't extend to the window edges.

After reading this http://effbot.org/tkinterbook/grid.htm

I tried playing around with other options, but can't get the label to move
any lower in the main window

self.label.grid(row=10, column=2, column=0)  didn't move the label any lower
than row 5

My main window isn't constructed using pack(), so I'm not mixing grid and
pack in this program.
Although, the main window isn't calling grid explicitly either- that's a bit
confusing, because I thought all widgets had to call grid or pack to be
displayed...

What args do I need to move the label to the bottom of the window, and
centered so it extends to both left and right edges?
I don't like to hard-code a row number, I'd rather make the label
dynamically be assigned to the bootm ros of the window, in case the window
grows or shrinks.


thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] e: moving from pack to grid in tkinter

2006-11-27 Thread Tony Cappellini

Date: Mon, 27 Nov 2006 18:07:33 +1300
From: "John Fouhy" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] moving from pack to grid in tkinter
To: tutor-python 
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 27/11/06, Tony Cappellini <[EMAIL PROTECTED]> wrote:

I've got a main window which is 640 * 400.
  self.root.geometry("600x400")

 self.label.pack(side=BOTTOM, fill=X)
This line would put the label at the bottom of the window, and extend to
both left and right edges of the window.



So, something like a status bar?

Yes exactly. I started with pack- and the status bar was ok.
Then I read the pdf at Effbot.org. I need to add several widgets to the main
frame, so I figured I would use grid for all of them.

Using pack() is really the easiest way to do this.  Here's what I'd do:



But i'm trying to get away from pack() and use grid()



Not sure why you have two column= options here.. One of them should be
columnspan, maybe?

Just a typi- I originally had columnspan, to see how it affected the widget-
it didnt'.
I was in the middle of an edit when I decided to post the message- but I had
tried cloumn with and without columnspan, no effect.


Using grid geometry, widgets will take their natural size and sit in
the middle of the cell you place them in.  If you want to override
this, you need to specify which edge or edges you want the widget to
stick to.



self.label.grid(row=5, column=0, columnspan=2, sticky=E+W)

I tried sticky E+W- again no effect on the edges of the label:(


f there is nothing in a row, the row will have a height of zero.  So

So how does one place a label (or any other widget) at the bottom row of a
screen using grid()?
It worked fine using pack- but the turoail pdf recommended grid() is easier
when working with several widgets in a common container widget


HTH!

Well thanks anyway. The pdf has really confused me.
Is there an official tkinter.org doc reference or something?

--
John.


--
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How To structure a program for cmd line mode & gui mode

2006-12-01 Thread Tony Cappellini

I"m writing a cmd line program which will automate getting some modules out
of cvs, based on some
input criteria.

Initiallly, I will do a cmd line version, but would like to make a gui
version later with QT.

I would like to find out how to structure the program so that when the gui
version is finised, it will still be fully functional in cmd line mode
(without gui).

The gui itself will be very simple- A listbox, and button or two.

python program.py

would run incmd line mode

python program.py -g

would run in gui mode.


How difficult is this to do? Can anyone think of a simple example of a
python app that runs in gui mode & cmd line mode?

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Docs for os popen and Popen2 modules

2006-12-05 Thread Tony Cappellini

Running python 2.3.4, on Windows XP

the popen2 docs show

6.8 popen2 -- Subprocesses with accessible I/O streams

This module allows you to spawn processes and connect to their
input/output/error pipes and >>obtain their return codes under Unix and
Windows.<<

Then it further goes to say

The only way to retrieve the return codes for the child processes is by
using the poll() or wait() methods on the Popen3 and Popen4 classes; these
are


only available on Unix<<.


This information is not available when using the popen2(), popen3(), and
popen4() functions, or the equivalent functions in the os
module.

After having spent much time reading about the differences between the popen
calls in the os module, and the popen calls in popen2, if the return values
aren't available under windows, I'm confused.

Why bother making these functions available under Windows at all? Other than
the order of the return values, I don't see any advantage of one over the
other.
Since the document contradicts itself regaring the return values on Windows,
is there a way to get the return values or not?
Is so- how?

Since poll and wait are only available on Unix, how do we wait for a process
to finish under Windows?

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Length of longest item in a list, using a list comp

2006-12-28 Thread Tony Cappellini

I want to use a list comp to get the length of the longest string in a list,
but can't quite get the syntax right.

l1=['abc', 'abcde', 'abcfdtea']

longest=0
[x for x in l1 if len(x) > longest]

The problem is I can't add the true clause to the if statement in a list
comp as in
if len(x) > longest:
  longest = len(x)


Is this possible using a list comp?


thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Length of longest item in a list, using a list comp

2006-12-28 Thread Tony Cappellini

Thanks,
but I am restricted to using 2.3.4 for now, so

longest = max([len(x) for x in ll])

works for me


On 12/28/06, Andreas Kostyrka <[EMAIL PROTECTED]> wrote:


* Python <[EMAIL PROTECTED]> [061228 20:44]:
> On Thu, 2006-12-28 at 11:27 -0800, Tony Cappellini wrote:
> >
> >
> > I want to use a list comp to get the length of the longest string in a
> > list, but can't quite get the syntax right.
> >
> > l1=['abc', 'abcde', 'abcfdtea']
> >
> > longest=0
> > [x for x in l1 if len(x) > longest]
>
> Use max to get the longest
>
> longest = max([len(x) for x in ll])
>
> With versions >= 2.4 you can omit the []
With 2.5 you can even do stuff like that:

>>> x=[range(5), range(3), range(7)]
>>> max(x, key=lambda i: len(i))
[0, 1, 2, 3, 4, 5, 6]
>>>

Andreas

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 34, Issue 55

2006-12-29 Thread Tony Cappellini

Message: 1
Date: Thu, 28 Dec 2006 17:24:41 -0800
From: "Chris Hengge" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] OT: Python 2.5 (Was Re: Length of longest item in


I hope this is related enough for this thread, but I'm curious why people
didn't seem to unanimously jump into 2.5 upon release.


One reason- having to upgrade all the packages that you've installed is time
consuming.

Another- we have a very large tools framework where I work. Someone needs to
make sure these tools will work with any new version of Python. We use
2.3at the  moment, and there is no significant reason to upgrade to
2.4 or 2.5, to justify the time involved in testing all the tools to make
sure every line of code is executed with the new version.

As far as my home use, I'm still using 2.4, and will keep it that way until
I need to install something that requires 2.5.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Starting python from a DOS prompt from any

2007-01-01 Thread Tony Cappellini

Message: 3
Date: Sun, 31 Dec 2006 00:10:39 -0500
From: "Daniel McQuay" <[EMAIL PROTECTED]>
Subject: [Tutor]  Starting python from a DOS prompt from any
  directory?

sorry for such a newbie question but i would like to figure this out

because

there are some situations where i need that to work from any directory.




Alan Gauld wrote

You need to set up your PATH environment variable to include the
python directory. You do this on XP(not so sure about Media Centre!)
via the MyComputer->Properties->Advanced->Environment Variables route
Once there you need to find the PATH variable and edit it to add the


I recommend adding it to the System Path environment variable, instead of
the Path Environment variable for your current  user login.
You'll have to reboot before it takes affect though.

There's also a simple registry change you can make to open the Python
interpreter in a specific directory, by right clicking on that directory
with Windows Explorer, without having to type 'cd' down a complicated path.
This saves time if you have long directory names.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 35, Issue 8

2007-01-03 Thread Tony Cappellini

Take a look at Movable Python.
It may not be exactly what you're looking for, but it may turn out to be a
resource to leverage from.

Message: 1
Date: Tue, 2 Jan 2007 21:14:16 -0500
From: "Daniel McQuay" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Starting python from a DOS prompt from any
  directory?


Nope, he said it was a networked PC but that Python was
in his D: drive, which I assumed was local. But that raises an
interesting proposition,. one that I've never tried. Is it possible
under Windows to install Python from machine A onto
a network drive and then run Python from machine B accessing
that drive? In other words does the installer need to do any magic
in the registry for Python to work or is it all just path setting
and shortcuts?

Can anyone confirm or otherwise the possibility?



i can try this under my networked drive tomorrow at school and if in fact
you can.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Embedding strings in a python script

2007-01-03 Thread Tony Cappellini

I have a number of text files which need to be checked into CVS.
Each file needs a special text header/footer in order that CVS can track
changes and version numbers.

Python to the rescue.

I've written a small python program which will write the header/footer to
all files in the current directory.

In order to do this, I need to add this string in my python program.

cvs_header='''
###
#
# $Header:$
#
# $Revision:$
# $Author:$
# $Date:$
#
'''

It works just fine.


However, the program which I wrote also needs to be kept under version
control.
When I make changes to that program, I noticed that the header above gets
modified by cvs, because it contains key variables which are recognized by
cvs.

This is unacceptable.

So I took this string out of my program, wrote it to a pickle file, and now
the pickle file is read at runtime, and the program will write the empty
header to the target files.
I can check the pickle files into cvs as binary files, and the header
strings will not be modified.

I now have 3 pickle files I need to distribute with the program, which is a
minor nuisance. Even using py2exe on Windows, these 3 files cannot be
embedded within the exe itself.

What I'd like to know, is there a way I can embed/endcode the cvs string
above in the python script, so that when that script is modified and checked
into cvs, that the cvs header string above will not be modified by cvs?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Embedding strings in a python script

2007-01-03 Thread Tony Cappellini

Message: 5
Date: Thu, 4 Jan 2007 16:13:51 +1300
From: "John Fouhy" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Embedding strings in a python script
To: tutor-python 
Message-ID:
  <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 04/01/07, Tony Cappellini <[EMAIL PROTECTED]> wrote:

What I'd like to know, is there a way I can embed/endcode the cvs string
above in the python script, so that when that script is modified and

checked

into cvs, that the cvs header string above will not be modified by cvs?


What about this:

cvs_header='''
###
#
# @Header:@

I will give that a try. I don't know if cvs keys off of the word, the $, or
the word surround by any two symbols.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Assigning a variable stored in a dictionary

2007-01-04 Thread Tony Cappellini

I can't see the forest through the trees.

I have stored 3 global variables in a dictionary, and associated each
variable with a filename.
Ideally, I want to read the contents of the text files, and store the
contents in the global variables. The globals will be used by another
function.
However, when I do the assignment to varname = fh.readlines(), a new
variable is created, and the reference to the global variable is
overwritten, because the contents of the files are strings, and strings are
immutable.

I see the problem, but not a good solution.


var1=""
var2=""
var3=""

def initGlobals():

   global var1, var2, var3

   fileDict = {'var1.txt':var1, 'var2.txt':var2, 'var3.txt':var3}

   for fn, varname in fileDict.iteritems():
   try:
   try:
   fh=open(fn, 'r')
   #id(varname) # at this point, this id matches the id of the
global variable
   varname = fh.readlines() # this creates a new variable, but
I want to store the file contents in the global var
   #id(varname)  # this is a new id, the global
var is not updated
   fh.close()
   except IOError:
   print "\nFATAL ERROR occurred reading %s\n" % fn
   finally:
   fh.close()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 35, Issue 18

2007-01-05 Thread Tony Cappellini

Message: 7
Date: Fri, 5 Jan 2007 08:04:23 -0800 (PST)
From: Mike Ellis <[EMAIL PROTECTED]>
Subject: [Tutor] Python gui for file input
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"

Hi all,

I am looking to create a simple gui interface to a small script.  The script
requires the user to input a directory.  I would like to allow the user to
browse the windows file system for the desired directory rather than type in
the full path by hand.  This would operate in much the same way as any
program when you select File>Open.  Is this possible to do with python?  Can
anyone point me in the proper direction to find more info on this or perhaps
an example script using a similar feature?

Thanks for your help,
Michael

If you're looking for a simple cross-paltform solution, EasyDialogs is by
far the easiest.
http://www.averdevelopment.com/python/EasyDialogs.html

You don't have to learn anything about any GUI framework. This will invoke
the native file open browser for Windows/Linux.
2-3 lines of code max.

It will
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Are there any MAC OSX python users here?

2007-01-20 Thread Tony Cappellini

I'm trying to help some people run a python cmd line program on OSX.

Would you email me off list if you have OSX and run python apps form the cmd
line?

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] reassigning/replacing sys.stdout

2007-01-30 Thread Tony Cappellini

I'm writing a python gui app that will call a python cmd line app. The gui
will take users input, pass it to the cmd line app, then display the cmd app
program output. The idea is to give users who aren't comfortable with the
cmd line a way to run the program, without having to open a shell window (on
Linux) or cmd prompt  (On Windows) and get hung up on syntax or shell
issues. It's a crutch.

The author of the cmd line app suggested I temporarily replace
sys.stdout'with a file descriptor class that can write directly to the
gui'.
The author is now out of communications for a few weeks,  so I can't
elaborate.

However, I've opened a file which writes to the disk, and replaced that
sys.stdout with that file descriptor.
I can then close and open that file and have the output of his program.
Now I can just put this in a textbox on the gui and display it to the user.

Writing to a file on disk, then reading it back in seems a bit clunky to me.
While I did somewhat do what the author had suggested (although I didn't
make a class out of the file descriptor), and it works, is there a better
way?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reassigning/replacing sys.stdout

2007-01-30 Thread Tony Cappellini

got it -thanks

On 1/30/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote:


Tony Cappellini wrote:
>
> I'm writing a python gui app that will call a python cmd line app. The
> gui will take users input, pass it to the cmd line app, then display
> the cmd app program output. The idea is to give users who aren't
> comfortable with the cmd line a way to run the program, without having
> to open a shell window (on Linux) or cmd prompt  (On Windows) and get
> hung up on syntax or shell issues. It's a crutch.
>
> The author of the cmd line app suggested I temporarily replace
> sys.stdout 'with a file descriptor class that can write directly to
> the gui'.
> The author is now out of communications for a few weeks,  so I can't
> elaborate.
>
> However, I've opened a file which writes to the disk, and replaced
> that sys.stdout with that file descriptor.
> I can then close and open that file and have the output of his program.
> Now I can just put this in a textbox on the gui and display it to the
> user.
>
> Writing to a file on disk, then reading it back in seems a bit clunky
> to me.
> While I did somewhat do what the author had suggested (although I
> didn't make a class out of the file descriptor), and it works, is
> there a better way?
print 'bob'
is the same as
sys.stdout.write('bob')
sys.stdout.write('\n')

In python, since this 'sys' function call doesn't check what type of
object it's calling,
just that it has a method called 'write', you can write your own object
and drop it in here.

E.G.

class GuiUpdater(object):
def write(astring):
#update your textbox here.

sys.stdout = GuiUpdater
print 'teststr'

Hmm, actually that might not work since it's not an instance of a class.
But that's the general idea/strategy.

HTH,
-Luke

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reassigning/replacing sys.stdout

2007-01-30 Thread Tony Cappellini

That would be ideal- but I'm using 2.4 now, and the people using the app
would also have to upgrade to 2.5.
I don't like upgrading unless there's a pressing need.


On 1/30/07, Danny Yoo <[EMAIL PROTECTED]> wrote:


> The author of the cmd line app suggested I temporarily replace
> sys.stdout'with a file descriptor class that can write directly to the
> gui'. The author is now out of communications for a few weeks, so I
> can't elaborate.

It sounds like the subprocess module might be very useful here:

 http://www.python.org/doc/lib/node529.html

The reason is because you can use the PIPE option, which gives you a
file-like object of the other process's stdout.  There's an example of
this in action here:

 http://www.python.org/doc/lib/node536.html

If you have more questions, please feel free to ask.  Best of wishes!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Purging/deleting the logfile with the logging module

2007-01-30 Thread Tony Cappellini

I want to purge (empty) or delete the logfile created by the logging module,
and reopen it for a new session.

There is reference to a close function in the 2.3 docs, but I don't see how
I can purge or delete the file, since I don't have access to the file
descriptor.
*close*( ) Tidy up any resources used by the handler. This version does
nothing and is intended to be implemented by subclasses. How can I
purge/delete & reopen the logfile?

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Purging/deleting the logfile with the logging module

2007-01-30 Thread Tony Cappellini

*close*(  )



>
> Tidy up any resources used by the handler. This version does nothing
> and is intended to be implemented by subclasses.
>
> How can I purge/delete & reopen the logfile?

>>FileHandler has a close() method that presumably does something useful.



see above-
It says it does nothing, but it does close the file. This is the first step.

Will see what the socket handler does.

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How does this work?

2007-02-06 Thread Tony Cappellini
I saw a snippet of python which is used to execute another python
script, and I'm trying to understand the mechanism. Simple as it is, I
don't understand how it works :-)


this is the caller
##
callee=open("tester.py").read()
exec(callee)
eval("main(['', 'argument'])")

##


this is the callee which is saved in tester.py
##
import sys

def main(arg):
   if arg != []:
  print"\nArgument is %s" % arg

if __name__ == "__main__"":
   main(sys.argv)
##

When the caller is executed

Argument is ['argument']
is displayed, as if the user had typed python tester.py

So I looked a the docs for read() in the file module for a clue-
didn't see anything obvious.
I usually use readlines() myself, so I thought read() might have some
hidden magic I wasn't aware of.

I understand exec() and eval() (in general), but I don't understand
how the entire tester.py gets read in when only a single call to
read() occurs.

Also- I don't understand how the call to eval() executes "in the scope
of" the main in tester.py. If  the main in the eval call were
*somehow* qualified with something to provide scope to tester.py, It
would probably make sense.

Let's assume that the caller also has a main(). How does eval() know
to execute main in the scope of tester.py, and not in the scope of the
caller?

This is pretty cool and confusing ;-)


Is this a useful thing to do, or bad in practice?

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How does this work?

2007-02-06 Thread Tony Cappellini
Hi Danny,


>
>
> Hi Tony,
>
> Ack!
>
> This is not safe.  I would strongly recommend not to do this.  There is a
> much simpler way for the caller to be written:
What is not safe about doing it this way ?

> 
> import tester
> tester.main([], "argument")
> 
>
> Done.  No tricks, no eval() or exec() necessary.

> Very Bad to do in practice.  It seems to be deliberately trying to be
> obfuscated.

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How does this work?

2007-02-07 Thread Tony Cappellini
>
> PS To import a file whose name is in a variable (string), see __import__().

I've started doing the import instead of exec/eval , but the person
who wrote the module being called, started using the logging module.
Now I can't capture the output of the module I'm calling, and display
it in a GUI. I was using popen() previously and that worked fine,
until he started using logging
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How does this work?

2007-02-07 Thread Tony Cappellini
> If I understand you, you have a python cmdline app that does something
> useful. You have users who aren't comfortable with the command line, so
> you are writing a GUI wrapper that calls the cmdline app with popen().
That is correct

> A better approach is to turn the functional part of the cmdline app -
> the code that does the real work - into an importable module.
it already is importable

>>Then your GUI app can import and use this module directly, instead
of doing hacks
> with popen() and stdout.

This all worked fine, until the author of the cmd line app stopped
using stdout and started using the logging module. Now I cannot
capture any output from his module.

> You don't even need a separate module for the cmdline app if it is
> written correctly - the command-line-specific part can be in an main()
> function that is only called if the module is run as main.

not totally true. It must be a stand-alone app, because there are
people using it now and many don't want to use the gui.
It is maintained completely independent of the gui by people other
than myself.. Any changes in the cmdline app should not affect the
gui. That was the intent by the author anyway. The use of the logging
module happens to be an exception to this.

Using popen() in a thread was a nice clean way to capture it's output.
Perhaps the exec/eval isn't so clean it's just what first came to mind.

I've already switched the exec/eval code to the import style.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How does this work?

2007-02-07 Thread Tony Cappellini
> The application needs to be rewritten if this is true.  The author's
> implementation is not logical,
regardless- I won't ask him to do this, it's just the way it is. I
don't know why it was written this way.

> if I'm inferring correctly that he knows there are other apps depending
> on this.
Yes he knows, but the gui aspect of it didn't come into play until the
app was deployed and already in use. He favors cmd line apps that can
be dasiy chained or piped together in the typical unix fashion.

> consider this:

> class Foo(object):
> def __init__(self):
> print "we're creating a new Foo and doing something useful here."
>
> if __name__ == "__main__":
> f = Foo()
> #we can do stuff with our Foo instance here.
I agree with this approach, and is how most of my apps begin.

> Now if we want to write a GUI for this, we just import this script, and
> use the Foo object to do whatever we were doing in the
> cmdline version -- no separate processes, threads, or any of that nastiness.
> Because it's imported, the contents of the 'if __name__...' conditional
> statement are never executed, so the cmdline functionality is disabled.

actually- after importing I call main directly and pass the cmd line
args specified by the user, through the gui

import targetapp

targetapp.main( [arg1, arg2]) # arg1 arg2 passed in through edit box in the gui
(this syntax may not be totally correct, just consider the concept. I
dont have my source in front of me.

> Hope that helps,
I understand your proposal, and agree with it. But I cannot change the
author's code, as he is the sole maintainer.

However, the problem now is more of an issue with the recent use of
the logging module in the target app, and not being able to capture
it's output, even though it is displayed on the screen.

Regardless of how the gui calls the target app, either by
instantiating a class or by calling main() after importing it- I am at
a loss as to how to "capture" the output on the screen which is now
put there by the logger, into put into a TextBox.

If implementing the target app as a class as you have suggested will
change this issue, then I am at a loss how it will work. I have used
the logging module at work, but in a more straightforward application,
and never had to deal with this kind of issue.

thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How does this work?

2007-02-07 Thread Tony Cappellini
> You should be able to make the logging module work with you, it is very
> flexible. You should hook into the logging module. Write a custom
> handler that pushes log methods into your GUI. Add the handler to the
> root logger.

The cmd line app already uses the logging module- this is where the
problem started.

At the moment- due to the author's implementation, I can't pass in
anything to modify ho the logger gets initialized. I have been
thinking about asking him to let me pass in an instance of the logger
to his main(), once I understand how to get the output from the logger
into a string variable


> Right, but the stand-alone stuff can be wrapped with
> if __name__=='__main__':

It already is. The cmd line app was written like this since day 1.
I am now importing it and calling his main() via the module import
import targetapp

targetapp.main([arg1, arg2]) or whatever

> leaving the part you care about available for import in the same module.

> The logging configuration should be in the main code as well, then when
> you import the module you can configure logging the way you want.

I think the hooks for the logging need to be changed, so I can pass
them in or call them.

Ok- now I will ask him to make his app a class
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How does this work?

2007-02-07 Thread Tony Cappellini
Thanks. I'm not using wx, but that doesn't matter.
I'll see if there's some way I can get the author to let me pass in the
logging handler to his main.

On 2/7/07, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Kent Johnson wrote:
> > You should be able to make the logging module work with you, it is very
> > flexible. You should hook into the logging module. Write a custom
> > handler that pushes log methods into your GUI. Add the handler to the
> > root logger.
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 37, Issue 15

2007-03-05 Thread Tony Cappellini
Rename your file from .py to .pyw.
This will prevent the DOS window from appearing

Message: 6
Date: Mon, 5 Mar 2007 16:51:42 +0100
From: learner404 <[EMAIL PROTECTED]>
Subject: [Tutor] Hiding/Killing a DOS window (from a previous
   os.system call)
To: "Tutor Python" 
Message-ID:
   <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"

Hello,

I'm launching an external app through an os.system() or os.popen() but I
don't want the resulting DOS window to hang-on there forever (my python
script is launched with pythonw):
I use a sys.exit() to kill the script who launched the external
app.Thepython script is killed, the app is launched, but the resulting
DOS window
is still there (I have the same result if I use the DOS tskill or taskkill
command to kill the script with his PID).

How could I hide/kill the resulting DOS window  from an os.sytem /
os.popenwith Python ?

Also is there a way to launch an external app. but without os.system and
os.popen to wait there but immediately continue to the next python line (to
avoid this I'm using a thread for now).

As an example I'm using this so far.
If I use pythonw to launch the script, notepad is launched, the script is
killed but the DOS window stay there.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HTTP file download

2007-03-13 Thread Tony Cappellini
How do you handle a binary file?

Message: 4
Date: Tue, 13 Mar 2007 13:23:44 +0100
From: "Jean-Philippe Durand" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] HTTP file download
To: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID:
   <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"

Hello Ronaldo,
Try this :

import urllib
mysock = urllib.urlopen("http://www.somesite.com/file";)
htmlSource = mysock.read()
mysock.close()
print htmlSource

Regards.
Jean-Philippe DURAND
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Make sound with python? Cross platform?

2008-03-10 Thread Tony Cappellini
>  Thanks very much. Not quite sure why I didn't find those earlier! I'll
>  have a look now.

I think this cuts more to the chase than using a game framework
http://pysonic.sourceforge.net/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-23 Thread Tony Cappellini
Kent

Would you show the examples which show where staticmethod &
classmethod are used?

I've often wondered about the usefulness of these myself. Having read
many of the popular books on python, none provide a good clear
explanation
of why or where these should be used, and what the alternatives are
(if any). They typically show an extremely terse example of the syntax
with little explanation.


Message: 7
Date: Sun, 23 Mar 2008 18:26:26 -0400
From: Kent Johnson <[EMAIL PROTECTED]>
Subject: Re: [Tutor] what is @classmethod and @staticmethod ??
To: maser <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

maser wrote:
> Thanks, Andreas. Why do we need to use classmethod/
> staticmethod and where do we need to use them ?

I use staticmethods as a convenience to put related functions in the
namespace of a class. Perhaps foo.py contains class Foo with
staticmethod bar(). In client code I can say

from foo import Foo
Foo.bar()

If bar was a module method it would be

from foo import Foo, bar
bar()


I prefer the former in cases where bar is related to Foo.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-23 Thread Tony Cappellini
>  I don't use classmethods so I can't discuss that. For staticmethods,
>  suppose I have in foo.py

Where is the word "staticmethod" in the example below? Where is it used?
This is what I was hoping to see.

>
>  class Foo(object):
># Lots of useful stuff
>
>
>  In client.py I have
>
>  from foo import Foo
>
>  # Do interesting things with Foo
>
>
>  Now perhaps I need a function
>  doSomethingRelatedToFoo()
>  that belongs in foo.py but doesn't have to be an instance method - it is
>  just a related function. I could make this a module function and change
>  client.py to read
>
>  from foo import Foo, doSomethingRelatedToFoo
>
>  doSomethingRelatedToFoo()
>
>
>  or I could make doSomethingRelatedToFoo a staticmethod, then I don't
>  have to change the import statement, I can access
>  doSomethingRelatedToFoo() through the already-imported Foo class:
>
>  Foo.doSomethingRelatedToFoo()
>
>  It's a pretty small difference but I like keeping the import simple and
>  not having to change it when I add doSomethingRelatedToFoo() to foo.py.
>
>  Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python to C++

2008-03-24 Thread Tony Cappellini
Another alternative is Weave
http://www.scipy.org/Weave

But mixing C/C++ with Python sort of defeats the reasons for using
Python to begin with

Message: 2
Date: Sat, 22 Mar 2008 02:44:54 +0100
From: Eike Welk <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Python to C++
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=utf-8

On Friday 21 March 2008 23:37, Dinesh B Vadhia wrote:
> Thank-you for all the suggestions for converting to C/C++ which
> will be followed up.
>
> Can we interface Python to a C++ library and if so how?
>
> Dinesh
>

If you have only few classes / member functions Boost-Python is a good
solution.
http://www.boost.org/libs/python/doc/

I heard that SWIG can also generate glue code for C++.
http://www.swig.org/Doc1.3/SWIGPlus.html

You could also look at Py-QT they have a tool like SWIG (SIP I think),
which they use to generate the glue code for the fairly big QT
library. Maybe you like it better.
http://www.riverbankcomputing.co.uk/pyqt/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python to C++

2008-03-25 Thread Tony Cappellini
Yes, but then you loose the clean Python readability, which is one of
the strong points for using Python


On Tue, Mar 25, 2008 at 2:46 AM, Andreas Kostyrka <[EMAIL PROTECTED]> wrote:
> Well, not exactly. Mixing Python with C/C++ extends the "coverage" that
>  you can do with Python.
>
>  Andreas
>
>
>  Am Montag, den 24.03.2008, 23:39 -0700 schrieb Tony Cappellini:
>
>
> > Another alternative is Weave
>  > http://www.scipy.org/Weave
>  >
>  > But mixing C/C++ with Python sort of defeats the reasons for using
>  > Python to begin with
>  >
>  > Message: 2
>  > Date: Sat, 22 Mar 2008 02:44:54 +0100
>  > From: Eike Welk <[EMAIL PROTECTED]>
>  > Subject: Re: [Tutor] Python to C++
>  > To: tutor@python.org
>  > Message-ID: <[EMAIL PROTECTED]>
>  > Content-Type: text/plain; charset=utf-8
>  >
>  > On Friday 21 March 2008 23:37, Dinesh B Vadhia wrote:
>  > > Thank-you for all the suggestions for converting to C/C++ which
>  > > will be followed up.
>  > >
>  > > Can we interface Python to a C++ library and if so how?
>  > >
>  > > Dinesh
>  > >
>  >
>  > If you have only few classes / member functions Boost-Python is a good
>  > solution.
>  > http://www.boost.org/libs/python/doc/
>  >
>  > I heard that SWIG can also generate glue code for C++.
>  > http://www.swig.org/Doc1.3/SWIGPlus.html
>  >
>  > You could also look at Py-QT they have a tool like SWIG (SIP I think),
>  > which they use to generate the glue code for the fairly big QT
>  > library. Maybe you like it better.
>  > http://www.riverbankcomputing.co.uk/pyqt/
>  > ___
>  > Tutor maillist  -  Tutor@python.org
>  > http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 49, Issue 78

2008-03-26 Thread Tony Cappellini
>>Draft notes for the next Kent's Korner presentation are available at
>>http://personalpages.tds.net/~kent37/kk/00010.html

>>Comments welcome.
I vote Kent move out of the korner and into the front of the classroom!

Nice color scheme, easy to look at, good layout, font, size, and small
chunks (paragraphs?) of info to digest without getting overwhelmed by
a page of content.

The page looks great.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Don't miss "Python-by-example - new online guide to

2008-04-04 Thread Tony Cappellini
 Date: Fri, 04 Apr 2008 07:12:11 -0700
From: Dick Moores <[EMAIL PROTECTED]>
Subject: [Tutor] Don't miss "Python-by-example - new online guide to
   Python Standard Library"
To: Python Tutor List 
Message-ID: <[EMAIL PROTECTED]>

Dick- there was no url with your message.

Also See Python Module Of The Week, by Doug Hellman
http://www.doughellmann.com/projects/PyMOTW/

Doug also has regular columns in Python Magazine-
http://pymag.phparch.com/
a great publication targeted mostly for beginner-intermediate level
Pythonistas
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Copy script

2008-04-10 Thread Tony Cappellini
Message: 7
Date: Thu, 10 Apr 2008 01:46:49 +0100
From: "Alan Gauld" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Copy script
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
   reply-type=original

>>I don;t see how the input file relates to the pdf files?
>>Which part of the pdf file does the input numbers refer to?

Kent, I believe the text file contains the name of the text files the author
wants to copy
The problem with the Windows console commands is I don't believe they have
the ability to read files for input.

Que
Here is some code that should get you started.
I don't see the name of the destination directory in your email, so you will
have to edit the variable 'destpath' in the code below
Indenting is likely to get changed during posting, so be aware of that.

import shutil
import os

sourceDir=''

for line in open('input.txt'):
if not sourceDir and ':' in line:
sourceDir = line[line.find(':')-1:]

if 'pdf' in line.lower():
filename = line.split(' ')[-1]
sourcePath = os.path.join(sourceDir, filename)
shutil.copyfile(sourcePath, destPath)
print'\nCopying %s' % sourcePath


print'\nCopy done'
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Copy script

2008-04-10 Thread Tony Cappellini
>>Of course they do - they can use input redirection just like Unix.
Oh,-I have forgotten about that.
But why use clunky batch language when you can use Python? After all, he did
post this to the python list.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 50, Issue 84

2008-04-29 Thread Tony Cappellini
I think you may have to send a message to the event look of you application
manually,
to let it know you have a key event for it. You may also need to temporarily
enable/disbale the keydown event handler for pyHook, or else you wont be
able to easily break out of  that code (at least I couldn't) :-)
You might want to post your message on the Python Win32 list. This issue is
specific to Window event handling and there are a lot of people on that
list who probably can help with this specific issue.

Message: 7
Date: Tue, 29 Apr 2008 12:46:29 +0530
From: "Muguntharaj Subramanian" <[EMAIL PROTECTED]>
Subject: [Tutor] pyHook related doubt
To: Tutor@python.org
Message-ID:
   <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="utf-8"

Hi All,
I am trying to create a custom keyboard driver program(like
http://www.tavultesoft.com/keyman/ ) for windows using python.
If this python script is run in the background, what is typed should be
converted into my native language.
For example if I hit 'a' in the keyboard, the output of the keyboard should
be a tamil unicode character(which will be pre-defined by user).

For making such program, i tried exploring pyHook based on this tutorial.
http://mindtrove.info/articles/monitoring-global-input-with-pyhook/

>From the tutorial, I have learned to capture the keys typed, but couldn't
understand how to change the keys before they reach the windows
applications.

Attached is the sample code I used (In this code basically i am trying to
change all the keys typed to 'b' in this code, but its not working )

Please guide me on how i can change the keys sent to the application using
pyHook. Or is there any other library that I can make use of to create such
application.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Memory Leak?

2008-05-07 Thread Tony Cappellini
 Message: 5
Date: Wed, 7 May 2008 16:18:23 -0400
From: "Michael Langford" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Memory Leak?
To: "Keith Suda-Cederquist" <[EMAIL PROTECTED]>
Cc: Python Tutor List 
Message-ID:
   <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"

>>You can always make a subclass of the classes you're thinking aren't being
>>garbage collected and put a print statement in their __del__ functions to
>>show you when they are. That will show you if/which objects aren't being
>>deleted.

Is this reliable or will this just confuse the issue?

Python in a Nutshell states "While gc itself can automatically fix many
leaks (as long as you avoid defining __del__ in your classes, since the
existence of __del__ can block cyclic garbage collection), your program runs
faster if it avoids creating cyclic garbage in the first place
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re Open a directory in the default file manager

2008-05-20 Thread Tony Cappellini
Message: 2
Date: Thu, 15 May 2008 20:10:05 +0200
From: Tim Michelsen <[EMAIL PROTECTED]>
Subject: [Tutor] Open a directory in the default file manager
To: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed

Hello,
>>is there any function/module that allows me to open a directory in the
>>default file manager of a operating system?

The os module gives you file & directory management functions, but not a
graphical file manager.
The os module also has many functions for spawning other processes



This doesn't open a File Manager- per se, it opens a platform independent
File Browser, and from it you can do some limited functions that a file
manager would.

Try EasyDialogs
(On Windows you need to install it first, it's part of the Mac python
distribution, but is not for Windows.

EasyDialogs.AskFolder

also

EasyDialogs.AskFileForOpen
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Open a directory in the default file manager

2008-05-20 Thread Tony Cappellini
*Tim Michelsen* timmichelsen at gmx-topmail.de

*Mon May 19 21:36:30 CEST 2008*

   - Previous message: [Tutor] Open a directory in the default file manager
   
   - Next message: [Tutor] Getting started with Python
   
   - *Messages sorted by:* [ date
] [
   thread ]
[
   subject ]
[
   author ]


**

>>I wasn't able to start explorer with os.startfile()

You need to use it like this
os.startfile('file.txt')

but it will launch the application associated with .TXT files- which
could be anything on Windows.
It wont launch Explorer unless you have Explorer associated with that extension.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Programming for the Absolute Beginner-OT

2008-05-28 Thread Tony Cappellini
A bit OT, but still within the realm of beginning Python...

My co-worker whom has just started learning Python, bought this book in used
condition.
http://www.courseptr.com/ptr_detail.cfm?group=Programming&subcat=Other&isbn=978%2D1%2D59863%2D112%2D8

Unfortunately it came without the CD, and the publisher does not have a link
for downloading the sources.

If you have this book AND the CD, please reply to me OFF-LIST.

I would like to get a copy of the files on the CD for my co-worker.

Thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Grabbing data from changing website

2008-06-05 Thread Tony Cappellini
--
>
> Message: 4
> Date: Wed, 4 Jun 2008 10:00:46 -0400
> From: James <[EMAIL PROTECTED]>
> Subject: [Tutor] Grabbing data from changing website
> To: tutor@python.org
> Message-ID:
><[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1
>
>
> >>urllib2 will grab the HTML. BeautifulSoup will parse it and allow
> >>fairly easy access. My writeup on each:



> I'll second Kent's vote for BeautifulSoup.

I had never done any web programming, but using BS I quickly wrote a small
program that downloads an image from a site.
The image changes daily, and the filename & directory are obviously unique.
BS made it very easy.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Is "var = None" in Python equivalent to "Set var

2008-06-29 Thread Tony Cappellini
Message: 9
Date: Sun, 29 Jun 2008 01:20:16 -0700
From: "wesley chun" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Is "var = None" in Python equivalent to "Set var
   =   Nothing"in VB?
To: [EMAIL PROTECTED], "Alan Gauld" <[EMAIL PROTECTED]>
Cc: tutor@python.org


>>the reason why i ask is because it's not standard practice i see
>>people doing this with Python,

Why? Since when is setting anything to None an outdated practice?
Does this mean checking an object to None is also outdated?

Setting it to None immediately puts the object in a state where the user
knows they need to
re-initialize it before using it again.

del will only reclaim that var at a later time, when the gc kicks in.

Of course, if that object won't be used again in the same scope, does it
really matter ?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Is "var = None" in Python equivalent to "Set var

2008-06-29 Thread Tony Cappellini
Wes,

is this not your reply?

"the reason why i ask is because it's not standard practice i see
people doing this with Python, so i'm trying to get a better
understanding of what you're trying to do.

thanks!
-- wesley"


> *exactly* why, other than most of the time, people let objects go
> out-of-scope and are reclaimed "naturally" or more rarely, i see
> people calling del on an object to remove it from the namespace
> explicitly. now, what i *do* see a lot is where a variable is
> originally initialized to None.
>
>
> > Since when is setting anything to None an outdated practice?
>
> >>not sure what you mean here, but i never said anything like this in my
> >>reply, nor was there any reference to anything being outdated.


The original author asked about the similarity between VB setting an object
to Nothing, and Python  vars being set to None

Your answer implies that this is an outdate practice (or not preferred) in
Python

>
> > Does this mean checking an object to None is also outdated?
>
> >>again, i'm not sure what you mean here as my reply never inferred
> >>this. although i am curious... how *do* you check an object to None?



> This was my own question, If you don't set an object to None- explicitly,
> then to you ever check to see if an object is None?



> >>you mean the variable. the only difference between this and using del

>>again, you said "var" but i'm assuming you mean object.

The original post referred to var, but a var is aon object- so I wasn't
consistant.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Is "var = None" in Python equivalent to "Set var

2008-06-30 Thread Tony Cappellini
 Message: 5
Date: Mon, 30 Jun 2008 11:49:59 +0200
From: "Andre Engels" <[EMAIL PROTECTED]>
Subject: Re: [Tutor] Is "var = None" in Python equivalent to "Set var
   =   Nothing"in VB?
To: Kelie <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID:
   <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=UTF-8

>>I don't know about Visual Basic,
In VB6 ( I have not worked with VB.NET), objects are set to Nothing when
they go out of scope, yet there is a fair amount lot of code out there where
objects are explicitly set to Nothing. This is a pretty common practice in
VB land.

>>but in Python these statements are unnecessary.
What happened to "Explicit is better than implicit"?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Is "var = None" in Python equivalent to "Set var

2008-06-30 Thread Tony Cappellini
This thread got a bit off track

> >>but in Python these statements are unnecessary.
> > What happened to "Explicit is better than implicit"?
>

Regarding the "original poster" contrasting VB with Python
setting someObject = None is perfectly fine in Python, and a good analogy
between the languages.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Wave module

2008-07-06 Thread Tony Cappellini
Message: 1
Date: Sat, 5 Jul 2008 16:50:35 -0600
From: "Alex Krycek" <[EMAIL PROTECTED]>
Subject: [Tutor] Wave module
To: tutor@python.org
Message-ID:
   <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="iso-8859-1"

Hello,

I'm trying to join two .wav files with the wave module. But when I try to
use wave.open(filename, "rb") I receive the following error:

Traceback (most recent call last):
 File "", line 1, in 
 File "F:\PortablePython1.0\lib\wave.py", line 483, in open
   return Wave_read(f)
 File "F:\PortablePython1.0\lib\wave.py", line 162, in __init__
   self.initfp(f)
 File "F:\PortablePython1.0\lib\wave.py", line 143, in initfp
   self._read_fmt_chunk(chunk)
 File "F:\PortablePython1.0\lib\wave.py", line 264, in _read_fmt_chunk
   raise Error, 'unknown format: %r' % (wFormatTag,)
wave.Error: unknown format: 85

I read somewhere that there are various wave formats, only some supported by
Python. Is this true? If so, is there any way I can convert my wave files
into a supported kind?


Thanks!


Try creating your own wave fiel and open it. It may be that the one you're
opening is corrupted.
http://www.sonicspot.com/guide/wavefiles.html

BTW Agent Krycec: what' that black, oily fluid in your eyes? ;-)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 53, Issue 18

2008-07-06 Thread Tony Cappellini
Message: 7
Date: Sat, 05 Jul 2008 12:23:36 -0600
From: Nathan Farrar <[EMAIL PROTECTED]>
Subject: [Tutor] Exploring the Standard Library
To: Python Tutor 
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="us-ascii"

>>I'd like to spend some time exploring the standard library.
This is somewhat tangent to your question, but I think it's an excellent
free resource for the modules in the Standard Library
http://www.doughellmann.com/projects/PyMOTW/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using sys.excepthook to handled unhandled exceptions

2008-08-27 Thread Tony Cappellini
The original authors left asserts in many places and I don't want the people
using the code to see the ugly tracebacks.
 want to add an unhandled exception handler to a large framework that I'm
maintaining, to make the applications behave better,

Users of a program shouldn't need to know anything about the language in
order to have an idea of what caused the error.

With that in mind, I thought I would add a handler which logs the tracebacks
to a file, display a 1-line message about the error on the screen, so the
user has some
idea of what happened, along with a simple message like this

"An unhandled exception has occured. This program will terminate. Please
email the "ErrorReport.txt" file to the developers"

I would like to hear from "people who have already assigned their own
function to sys.excepthook" as to how they approached this problem, and what
issues they encountered, if any.


Thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using sys.excepthook to handle unhandled exception (corrected and reposted)

2008-08-27 Thread Tony Cappellini
I'm maintaining a large framework of python code where the original
authors left many assert statements.

When an unhandled exception occurs, the traceback is displayed on the
screen. Ideally, I don't want the users to see the tracebacks
from unhandled exceptions, but rather a short, useful message.

Users of a program shouldn't need to know anything about the language
the program was written in order to have an idea of what caused the
error.

I want to add an "unhandled exception handler" which logs the
tracebacks to a file, display a 1 line message as to where or why the
exception occurred.
Assigning my exception logger function to sys.excepthook is what I have in mind.

This exception logger will also display a message like this.
"An unhandled exception has occurred. This program will terminate.
Please email the "ErrorReport.txt" file to the developers"

Adding a function to log the tracebacks is easy, I'm more interested
in the side affects caused by assigning a function to sys.excepthook.
The framework I'm maintaining does NOT already use sys.excepthook.
That is a good beginning. ;-)

I would like to hear from the experiences of people "who have assigned
an exception handler function to sys.excepthook" as to how they
approached
this problem. More specifically, what issues they encountered, if any.



Thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] cmd module

2008-09-03 Thread Tony Cappellini
I was just reading the PYMOTW article on the cmd module, and trying
the examples.

http://www.doughellmann.com/PyMOTW/cmd/cmd.html

Scroll down to Auto-Completion.

Does the tab key work for anyone running Windows ?
Is this an OS specific feature?

I see the bash prompts in the article, tab does something different
when running on Linux.

I'm running Windows XP - when I run this example, tab only moves the
cursor over, not the auto completion.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using the curses module (or a better solution)

2008-10-06 Thread Tony Cappellini
I'm maintaining a framework of tests which are run on a diskless Linux
client, in character mode (no graphical desktop).

The tests often print out a lot of info, which scrolls off the screen.

I'd like to add a 1-2 line no-scroll-area at the top of the screen, so as to
print a message which indicates the progress of the current test.

I am thinking about using the Python curses module for this, unless someone
would suggest an alternative solution, although I'm not sure if the curses
module
has this non-scroll area capability.

http://www.amk.ca/python/howto/curses/

Ideally I'd like something which works on Windows & Linux, but since the
test environment on Linux is non-graphical, packages like WxPython can't be
used.


Thanks
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Using the curses module (or a better solution)

2008-10-06 Thread Tony Cappellini
> See the recent discussion of urwid for discussion of a similar problem.
> http://thread.gmane.org/gmane.comp.python.tutor/50500/
This looks interesting.

Thanks!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Determining periodicity of rand.randint()

2009-01-31 Thread Tony Cappellini
Has anyone ever measured how random (or deterministic) a given sequence of
numbers generated by rand.randint() are?

Using these arguments for rand.randint(0, 1000 )
if a program which calls rand.randint() runs for 10 hours (or a few days),
will it keep generating a repeatable set of numbers at some point? I'm
trying to understand the periodicity (or lack of) of the numbers generated
by rand.randint()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor