Re: [Tutor] droplet like behaviour in Python

2009-08-10 Thread Alan Gauld
"pedro"  wrote 


Well I made a script called droplet.py which looks like this:

#!/usr/bin/env python
# encoding: utf-8
import sys
theFilePath = sys.argv[1]
print theFilePath


But when I try to drop something on it nothing happens. Sorry I guess 
there is something fundamental that I am missing.


Sorry, obviously I was wrong. 
FWIW in XP I get python to start up but there is no filename in argv.
I'll go and have a hunt in my MacOS books but sadly I don't have 
my iBook available just now to try anything.


Alan G.

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


Re: [Tutor] droplet like behaviour in Python

2009-08-10 Thread Wayne
On Mon, Aug 10, 2009 at 2:52 AM, Alan Gauld wrote:

> "pedro"  wrote
>
>> Well I made a script called droplet.py which looks like this:
>>
>> #!/usr/bin/env python
>> # encoding: utf-8
>> import sys
>> theFilePath = sys.argv[1]
>> print theFilePath
>>
>>
>> But when I try to drop something on it nothing happens. Sorry I guess
>> there is something fundamental that I am missing.
>>
>
> Sorry, obviously I was wrong. FWIW in XP I get python to start up but there
> is no filename in argv.
> I'll go and have a hunt in my MacOS books but sadly I don't have my iBook
> available just now to try anything.


I'm not sure if this will be of any help:

 http://docs.python.org/library/carbon.html

http://sourceforge.net/projects/appscript/

But that's all I could come up with, without a mac or a whole lot of
experience with a mac.

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


Re: [Tutor] droplet like behaviour in Python

2009-08-10 Thread bob gailer

Alan Gauld wrote:

"pedro"  wrote

Well I made a script called droplet.py which looks like this:

#!/usr/bin/env python
# encoding: utf-8
import sys
theFilePath = sys.argv[1]
print theFilePath


But when I try to drop something on it nothing happens. Sorry I guess 
there is something fundamental that I am missing.


Sorry, obviously I was wrong. FWIW in XP I get python to start up but 
there is no filename in argv. 


That depends on the file association settings for .py.
Start -> Settings -> Control Panel -> Folder Options -> File Types
Find py extension.
Click Advanced
Choose open
Click Edit
in my system I see "H:\Python30\python.exe" "%1" %*
which means fire up python.exe, pass the dropped file name as the first 
argument.


BTW a nice 1 python line version independent droplet:
#!/usr/bin/env python
# encoding: utf-8
input(__import__('sys').argv)


--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] MySQLdb field type

2009-08-10 Thread Rick Pasotto
After executing a query that returns values, cursor.description contains
a list of tuples, one tuple for each field. Each tuple has seven values
consisting of 
(name,type_code,display_size,internal_size,precision,scale,null_ok).

Where can I find a listing of what the various type_codes are? Do I need
to experiment and make my own list?

-- 
"As empty vessels make the loudest sound, so they that have
 the least wit are the greatest blabbers." -- Plato
Rick Pasottor...@niof.nethttp://www.niof.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] MySQLdb field type

2009-08-10 Thread Kent Johnson
On Mon, Aug 10, 2009 at 1:08 PM, Rick Pasotto wrote:
> After executing a query that returns values, cursor.description contains
> a list of tuples, one tuple for each field. Each tuple has seven values
> consisting of 
> (name,type_code,display_size,internal_size,precision,scale,null_ok).
>
> Where can I find a listing of what the various type_codes are? Do I need
> to experiment and make my own list?

See the section "Type Objects and Constructors" in the DB-API spec:
http://dinsdale.python.org/dev/peps/pep-0249/

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


Re: [Tutor] MySQLdb field type

2009-08-10 Thread Rick Pasotto
On Mon, Aug 10, 2009 at 02:50:01PM -0400, Kent Johnson wrote:
> On Mon, Aug 10, 2009 at 1:08 PM, Rick Pasotto wrote:
> > After executing a query that returns values, cursor.description contains
> > a list of tuples, one tuple for each field. Each tuple has seven values
> > consisting of 
> > (name,type_code,display_size,internal_size,precision,scale,null_ok).
> >
> > Where can I find a listing of what the various type_codes are? Do I need
> > to experiment and make my own list?
> 
> See the section "Type Objects and Constructors" in the DB-API spec:
> http://dinsdale.python.org/dev/peps/pep-0249/

Not exactly what I'm looking for.

The type_code in the tuple is a number. For one of my tables I see the
following numbers: 1, 2, 10, 252, 253, 254. What I wanted was a listing
telling me which number was which type_code.

-- 
"The dichotomy between personal liberties and property rights is a false
 one. Property does not have rights. People have rights. ... In fact, a
 fundamental interdependence exists between the personal right to liberty
 and the personal right to property." -- Potter Stewart, U.S. Supreme Court
 Justice, Lynch v. Household Finance Corp., 1972
Rick Pasottor...@niof.nethttp://www.niof.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tutorial update

2009-08-10 Thread Alan Gauld
Just a note to say that the v3.1 version of my tutor has reached another 
milestone.
I just uploaded the last topic in the Basics section which means the 
tutorial is
now sufficiently complete that it could be used by a beginner to learn V3 
Python.


It hasn't had enough traffic to call it good quality yet - I'm sure there 
are lots of

mistakes to find - but its definitely useable.

The remaining two sections will progress and my usual snails pace :-(
Then I might get started on finishing the remaining topics in the 
Applications

section - andmaybe even add a few more new ones!.

Enjoy,

Alan G. 



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


Re: [Tutor] Tutorial update

2009-08-10 Thread Alan Gauld


"Alan Gauld"  wrote 

I just uploaded the last topic in the Basics section which means the 
tutorial is now sufficiently complete that it could be used by a 
beginner to learn V3 Python.




And the v3  url is, of course:

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/l2p/

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


[Tutor] Fixing "nearly ASCII" data file?

2009-08-10 Thread Allen Fowler

Hello,

I have some CSV data from Office / OpenOffice in "nearly ASCII" format.  This 
is just basic text but it it stored as UTF-8, and has curly quotes, etc.

Is there a way to easily read the file as ASCII by forcing these to the 
standard ASCII equivalents?

Thank you


  

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


Re: [Tutor] Fixing "nearly ASCII" data file?

2009-08-10 Thread John Krukoff
On Mon, 2009-08-10 at 15:34 -0700, Allen Fowler wrote:
> Hello,
> 
> I have some CSV data from Office / OpenOffice in "nearly ASCII" format.  This 
> is just basic text but it it stored as UTF-8, and has curly quotes, etc.
> 
> Is there a way to easily read the file as ASCII by forcing these to the 
> standard ASCII equivalents?
> 
> Thank you

I found this library "ASCII, Dammit", from the author of Beautiful Soup,
to be a good starting point when I had to write my own force to ASCII
conversion routine, maybe it'll work for you too:

http://www.crummy.com/cgi-bin/msm/map.cgi/ASCII%2C+Dammit

-- 
John Krukoff 
Land Title Guarantee Company

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


Re: [Tutor] Fixing "nearly ASCII" data file?

2009-08-10 Thread Alan Gauld


"Allen Fowler"  wrote


I have some CSV data from Office / OpenOffice in "nearly ASCII" format.
This is just basic text but it it stored as UTF-8, and has curly quotes, 
etc.


Is there a way to easily read the file as ASCII by forcing these to the 
standard ASCII equivalents?


You should be able to process it using the string translation methods with
a one to one conversion.

try help(''.translate)

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



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


Re: [Tutor] MySQLdb field type

2009-08-10 Thread Kent Johnson
On Mon, Aug 10, 2009 at 3:52 PM, Rick Pasotto wrote:
> Not exactly what I'm looking for.
>
> The type_code in the tuple is a number. For one of my tables I see the
> following numbers: 1, 2, 10, 252, 253, 254. What I wanted was a listing
> telling me which number was which type_code.

Ah, right. I guess this will vary for different db modules. Which one
are you using?

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


Re: [Tutor] monitor number of files in a folder

2009-08-10 Thread Jeff Younker

On Aug 7, 2009, at 9:29 AM, pedro wrote:

On my machine (a Mac), os.listdir does include files that begin with  
"." Having the while loop timeout after 10 or 20 times through as  
was suggested a couple posts back will work fine for my particular  
situation.

Thanks


Yes, it does include files that begin with '.', but it does not include
the entries '.' and '..'.

-jeff

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


Re: [Tutor] droplet like behaviour in Python

2009-08-10 Thread Dave Angel

bob gailer wrote:
Alan 
Gauld wrote:

"pedro"  wrote

Well I made a script called droplet.py which looks like this:

#!/usr/bin/env python
# encoding: utf-8
import sys
theFilePath = sys.argv[1]
print theFilePath


But when I try to drop something on it nothing happens. Sorry I 
guess there is something fundamental that I am missing.


Sorry, obviously I was wrong. FWIW in XP I get python to start up but 
there is no filename in argv. 


That depends on the file association settings for .py.
Start -> Settings -> Control Panel -> Folder Options -> File Types
Find py extension.
Click Advanced
Choose open
Click Edit
in my system I see "H:\Python30\python.exe" "%1" %*
which means fire up python.exe, pass the dropped file name as the 
first argument.


BTW a nice 1 python line version independent droplet:
#!/usr/bin/env python
# encoding: utf-8
input(__import__('sys').argv)


Unfortunately, you're not describing a droplet, but only the usual 
Windows file association scheme.  (Incidentally, the OP was asking about 
the Mac)


The filename that goes into the %1 of the shortcut is the name of the 
script.  So that will show up in sys.argv[0].  The OP wanted to drop a 
data file, and have its name show up as sys.argv[1].


I don't know the Mac, so I stayed out of this thread.  But I haven't 
found any way to do real Python droplets on Windows.  Closest I found 
was adding my python app to the right-click menu, so one can right-click 
on a data file to get the Python code to run on it.


What a droplet needs is for the user to be able to drag a data file to a 
python script, and have the script start, with sys.argv[1] pointing to 
the data file.   I'd love to know how to do it in Windows, and the OP 
would love to know how to do it on the Mac.


DaveA

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


Re: [Tutor] droplet like behaviour in Python

2009-08-10 Thread pedro

On 2009-08-10 22:40:14 -0400, Dave Angel  said:


bob gailer wrote:

Alan
Gauld wrote:

"pedro"  wrote

Well I made a script called droplet.py which looks like this:

#!/usr/bin/env python
# encoding: utf-8
import sys
theFilePath = sys.argv[1]
print theFilePath


But when I try to drop something on it nothing happens. Sorry I
guess there is something fundamental that I am missing.


Sorry, obviously I was wrong. FWIW in XP I get python to start up but
there is no filename in argv.


That depends on the file association settings for .py.
Start -> Settings -> Control Panel -> Folder Options -> File Types
Find py extension.
Click Advanced
Choose open
Click Edit
in my system I see "H:\Python30\python.exe" "%1" %*
which means fire up python.exe, pass the dropped file name as the
first argument.

BTW a nice 1 python line version independent droplet:
#!/usr/bin/env python
# encoding: utf-8
input(__import__('sys').argv)



Unfortunately, you're not describing a droplet, but only the usual
Windows file association scheme.  (Incidentally, the OP was asking about
the Mac)

The filename that goes into the %1 of the shortcut is the name of the
script.  So that will show up in sys.argv[0].  The OP wanted to drop a
data file, and have its name show up as sys.argv[1].

I don't know the Mac, so I stayed out of this thread.  But I haven't
found any way to do real Python droplets on Windows.  Closest I found
was adding my python app to the right-click menu, so one can right-click
on a data file to get the Python code to run on it.

What a droplet needs is for the user to be able to drag a data file to a
python script, and have the script start, with sys.argv[1] pointing to
the data file.   I'd love to know how to do it in Windows, and the OP
would love to know how to do it on the Mac.

DaveA

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


Exactly, thanks for clarifying Dave.
Pete


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


[Tutor] run python script on another computer's terminal (LAN)

2009-08-10 Thread pedro
Hi, does anyone know how to send a command that is within a python 
script to another computer's terminal. This is what it looks like in 
Applescript.


tell application "Terminal" of machine 
"eppc://USERNAME:passw...@computer2.local"

do script "ls"
end tell



I basically want os.system('ls') to be run on another computer in my LAN.

Merci
Pete


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