Re: [Tutor] easy way to populate a dict with functions

2009-08-11 Thread Albert-Jan Roskam
Hi Bob,

Sorry for the late reply, but thank you for your code. I still haven't 
completely wrappped my brain around decorator functions, but thanks to your 
reply at least now my frontal lobe is touching it. ;-)

Re: the ordering of functions: I thought it mattered because the inspect module 
returns a list of two-tuples (in this case, a list of four two-tuples). 
Therefore, e.g. option #1 should always cause the same function to be run. But 
apparently I'm wrong here somewhere.

Best wishes,
Albert-Jan
Netherlands 

--- On Thu, 8/6/09, bob gailer  wrote:

> From: bob gailer 
> Subject: Re: [Tutor] easy way to populate a dict with functions
> To: "Albert-Jan Roskam" 
> Cc: "tutorpythonmailinglist Python" 
> Date: Thursday, August 6, 2009, 10:20 PM
> Albert-Jan Roskam wrote:
> > Hi Bob,
> > 
> > Very neat solution, thanks a lot! I didn't know the
> inspect module, but it's just what's needed here. Cool! 
> 
> Great.
> 
> Regarding the ordering of functions in the list - variable
> names in namespaces (such as modules) are stored in
> dictionaries. Any ordering is lost in this process. Why is
> order important to you here?
> 
> There are other things that could be said about your
> program and my revision.
> 
> 1 - it is better to have functions return values and have
> the main program decide whether to print them or take some
> other action. (Also note you were not consistent - foo
> returns the others print!)
> 
> 2 - since the list contains the function names as well as
> references to the functions you could present the names to
> the user. You could even ask the user to enter the first
> letter(s) of the names instead of a number.
> 
> 3 - with a slight enhancement to things you can preserve
> the order:
> 
> #  commands.py ---
> cmds = [] 
> def collect(func):
>  'a "decorator" that adds each function to the cmds list'
>  cmds.append((func.__name__, func))
> 
> @collect
> def foo (a):
> return "foo" * a
> 
> @collect
> def bletch (q):
> for i in range(20):
>   return i * q
> 
> @collect
> def stilton (n):
> return "yes sir, " * n
> 
> @collect
> def romans (z):
> return "what have the romans really done for us?\n" * z
> 
> #  end code ---
> 
> #  main.py ---
> import commands
> cmds = commands.cmds
> 
> # etc.
> 
> -- Bob Gailer
> Chapel Hill NC
> 919-636-4239
> 


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


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

2009-08-11 Thread Alan Gauld

"pedro"  wrote

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



You might be better asking these kind of questions on the MacPython 
mailing lists/forums since more folks there will be familiar with what 
are fairly MacOS specific issues. Also you can get Python to talk to 
Applescript which might be the easiest way...


However in a general sense you can use ssh (or rsh?) to do that.
You might also be able to avoid using subprocess or os.system 
by mounting the remote filesystem? That would let you you

os.listdir() on the remote machine?

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


[Tutor] To write data in two different fonts?

2009-08-11 Thread prasad rao
Hello
 I am wtriting some dat on to a file in which
headings should be of different size than other data.
Is it possible?If possible please tell me how to do it.



def sc(adir):
  import os,myfiles
  dest=open('C:/scripts.txt','w')
  s=myfiles.myfiles(adir)
  for x in s:
 if os.path.isfile(x):
 sorce=open(x,'r')
 data=sorce.readlines()
 dest.write(x+'\n','bold')

 dest.write(('-'*len(x))+'\n')
 for l in data:
  dest.write(l)
 sorce.close()
   else:pass
   dest.close()


>>> sc('C:\Python26\mscripts')

Traceback (most recent call last):
  File "", line 1, in 
sc('C:\Python26\mscripts')
  File "", line 9, in sc
dest.write(x+'\n','bold')
TypeError: function takes exactly 1 argument (2 given)


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


Re: [Tutor] To write data in two different fonts?

2009-08-11 Thread Kent Johnson
On Tue, Aug 11, 2009 at 5:24 AM, prasad rao wrote:
> Hello
>  I am wtriting some dat on to a file in which
> headings should be of different size than other data.
> Is it possible?If possible please tell me how to do it.
>
> 
>
> def sc(adir):
>   import os,myfiles
>   dest=open('C:/scripts.txt','w')
>   s=myfiles.myfiles(adir)
>   for x in s:
>  if os.path.isfile(x):
>  sorce=open(x,'r')
>  data=sorce.readlines()
>  dest.write(x+'\n','bold')
>
>  dest.write(('-'*len(x))+'\n')
>  for l in data:
>   dest.write(l)
>  sorce.close()
>    else:pass
>    dest.close()

Plain text files don't have style information. You have to write
structured data such as HTML or PDF. HTML is probably the simplest.

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


Re: [Tutor] To write data in two different fonts?

2009-08-11 Thread Dave Angel

prasad rao wrote:

Hello
 I am wtriting some dat on to a file in which
headings should be of different size than other data.
Is it possible?If possible please tell me how to do it.



def sc(adir):
  import os,myfiles
  dest=open('C:/scripts.txt','w')
  s=myfiles.myfiles(adir)
  for x in s:
 if os.path.isfile(x):
 sorce=open(x,'r')
 data=sorce.readlines()
 dest.write(x+'\n','bold')

 dest.write(('-'*len(x))+'\n')
 for l in data:
  dest.write(l)
 sorce.close()
   else:pass
   dest.close()


  

sc('C:\Python26\mscripts')



Traceback (most recent call last):
  File "", line 1, in 
sc('C:\Python26\mscripts')
  File "", line 9, in sc
dest.write(x+'\n','bold')
TypeError: function takes exactly 1 argument (2 given)



  
I figure you're asking two questions here.  First is the syntax error.  
All you need to do to fix that is to combine the strings in the write() 
function into a single string, instead of trying to pass two separate 
arguments.  So change from:


dest.write(x+'\n','bold')
to

dest.write(x + '\n' + 'bold')


The second question was harder for me to understand.  Finally, I noticed 
the subject line, which made it clear what you meant by "different 
size."  I had been assuming you meant "different number of characters."


You're writing a text file here, and plain text files have no notion of 
fonts.  Without knowing the contents/format of the files you're 
combining, and/or the kind of program that's going to be interpreting 
this resulting file, I could only make wild guesses.



If all the source files are html pieces, and the resultant file is to be 
interpreted as html, you could put  and  around the text you 
wanted to be bold.  But of course, you'd have lots of other formatting 
text, just to be a valid html file.


If the result file is supposed to be rtf  (to be displayed in Wordpad, 
or WinWord), you could put its escape sequences in it.  I'm sure there's 
a spec for rtf out there somewhere in internet land.


If the result file is to be printed by an ancient Epson MX80 printer I  
sort-of recall, you'd put \x0e before the part you wanted bold, and \x0f 
after it.  Or something like that.


If the resultant file is a message for this newsgroup, you could put an 
asterisk before and after the part you want bold.  I think you have to 
do it for each "word," but I've never seen a spec on it.


But if the files are pure printable text files, and the result is to be 
viewable in Notepad, Metapad, or the like, then it can't be done, to the 
best of my knowledge.



DaveA

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


[Tutor] list question

2009-08-11 Thread proportional
hi i am currently doing the 'livewires' python tutorial lesson 5. i am making a 
little game that makes a few squares chase a circle around a little grid. i can 
get the 1 square acting on 1 variable to come up, but the tutorial now wants me 
to create a list of variables that act under the same class.

this is what i have to make the 1 square appear (which works)(i have also cut a 
lot of the program out to make this email smaller.)

class Robot:
pass

def place_robot():
global robot
robot = Robot()
robot.x=random_between(0,63)
robot.y=random_between(0,47)
draw_robot()
print robot.x 

and i cant figure out what to write to make the variable 'robot' work as a 
list, and then follow all the instructions 3 times. this is what i tried to put 
in.

class Robot:
pass

def place_robot():
global robot
r1 = Robot()
r2 = Robot()
r3 = Robot()
robot = [r1,r2,r3]
robot.x=random_between(0,63)
robot.y=random_between(0,47)
draw_robot()
print robot.x 

i was under the assumption that the instruction robot.x=random_between(0,63) 
would return a value 3 times for r1 r2 and r3, but instead i get 
AttributeError: 'list' object has no attribute 'x'. so i got no idea heh. i 
hope this makes sense, as im really new to programming. thanks if anyone can 
help.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list question

2009-08-11 Thread Ataulla S H
On Tue, Aug 11, 2009 at 5:47 PM,  wrote:

>  hi i am currently doing the 'livewires' python tutorial lesson 5. i am
> making a little game that makes a few squares chase a circle around a little
> grid. i can get the 1 square acting on 1 variable to come up, but the
> tutorial now wants me to create a list of variables that act under the same
> class.
>
> this is what i have to make the 1 square appear (which works)(i have also
> cut a lot of the program out to make this email smaller.)
>
> class Robot:
> pass
>
> def place_robot():
> global robot
> robot = Robot()
> robot.x=random_between(0,63)
> robot.y=random_between(0,47)
> draw_robot()
> print robot.x
>
> and i cant figure out what to write to make the variable 'robot' work as a
> list, and then follow all the instructions 3 times. this is what i tried to
> put in.
>
> class Robot:
> pass
>
> def place_robot():
> global robot
> r1 = Robot()
> r2 = Robot()
> r3 = Robot()
> robot = [r1,r2,r3]
>
  mydict = {}
  x=random_between(0,63)
  y=random_between(0,47)
 mydict[str(robot)] = {'x':x,'y':y}


> #robot.x=random_between(0,63)
> # robot.y=random_between(0,47)
> draw_robot()
> print robot.x
>
> i was under the assumption that the instruction
> robot.x=random_between(0,63) would return a value 3 times for r1 r2 and r3,
> but instead i get AttributeError: 'list' object has no attribute 'x'. so i
> got no idea heh. i hope this makes sense, as im really new to programming.
> thanks if anyone can help.
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Ataulla SH

web:www.kring.com
personal blog:www.ataulla.objectis.net
KRING Technologies India Pvt. Ltd.
1st Floor, Tower B, Infinity Towers, DLF II, Gurgaon-122 002
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list question

2009-08-11 Thread Wayne
On Tue, Aug 11, 2009 at 7:17 AM,  wrote:

>  hi i am currently doing the 'livewires' python tutorial lesson 5. i am
> making a little game that makes a few squares chase a circle around a little
> grid. i can get the 1 square acting on 1 variable to come up, but the
> tutorial now wants me to create a list of variables that act under the same
> class.
>
> this is what i have to make the 1 square appear (which works)(i have also
> cut a lot of the program out to make this email smaller.)
>
> class Robot:
> pass
>
> def place_robot():
> global robot
> robot = Robot()
> robot.x=random_between(0,63)
> robot.y=random_between(0,47)
> draw_robot()
> print robot.x
>
> and i cant figure out what to write to make the variable 'robot' work as a
> list, and then follow all the instructions 3 times. this is what i tried to
> put in.
>
> class Robot:
> pass
>
> def place_robot():
> global robot
> r1 = Robot()
> r2 = Robot()
> r3 = Robot()
> robot = [r1,r2,r3]
> robot.x=random_between(0,63)
> robot.y=random_between(0,47)
> draw_robot()
> print robot.x
>
> i was under the assumption that the instruction
> robot.x=random_between(0,63) would return a value 3 times for r1 r2 and r3,
> but instead i get AttributeError: 'list' object has no attribute 'x'. so i
> got no idea heh. i hope this makes sense, as im really new to programming.
>

I think what you want is:

for r in robot:
r.x = random_between(0,63)
r.y = random_between(0,47)
draw_robot()
print r.x

Now for the why:
robot is a list of objects - you declared it such with robot = [r1, r2, r3]
(incidentally you could just do robots = [Robot(), Robot(), Robot()] ), and
lists don't have x y attributes, which you're trying to access. I presume
you're really trying to access the x y attributes of your Robot() class,
which is an entirely different object from your list.

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


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

2009-08-11 Thread pedro

On 2009-08-11 05:27:19 -0400, "Alan Gauld"  said:


"pedro"  wrote


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



You might be better asking these kind of questions on the MacPython
mailing lists/forums since more folks there will be familiar with what
are fairly MacOS specific issues. Also you can get Python to talk to
Applescript which might be the easiest way...

However in a general sense you can use ssh (or rsh?) to do that.
You might also be able to avoid using subprocess or os.system
by mounting the remote filesystem? That would let you you
os.listdir() on the remote machine?

HTH


Hi Alan, I am trying to make my code as cross-platform as possible, so 
I am trying to avoid Applescript altogether. I'll try out your ssh 
suggestion and mounting the remote filesystem?

Thanks
Pete


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


Re: [Tutor] list question

2009-08-11 Thread Ataulla S H
if u want to add new attributes into ur list
u need to import list object in ur class

class customlist(list):
 x = 'your val'
c = customlist()
>>> dir(c)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
'__delslice__', '__dict__', '__doc__', '__eq__', '__ge__',
'__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__',
'__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__',
'__lt__', '__module__', '__mul__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__',
'__setitem__', '__setslice__', '__str__', '__weakref__', 'append', 'count',
'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort', *'x'*]
>>> c.x
'your val'

On Tue, Aug 11, 2009 at 6:25 PM, Wayne  wrote:

>
>
> On Tue, Aug 11, 2009 at 7:17 AM,  wrote:
>
>>  hi i am currently doing the 'livewires' python tutorial lesson 5. i am
>> making a little game that makes a few squares chase a circle around a little
>> grid. i can get the 1 square acting on 1 variable to come up, but the
>> tutorial now wants me to create a list of variables that act under the same
>> class.
>>
>> this is what i have to make the 1 square appear (which works)(i have also
>> cut a lot of the program out to make this email smaller.)
>>
>> class Robot:
>> pass
>>
>> def place_robot():
>> global robot
>> robot = Robot()
>> robot.x=random_between(0,63)
>> robot.y=random_between(0,47)
>> draw_robot()
>> print robot.x
>>
>> and i cant figure out what to write to make the variable 'robot' work as a
>> list, and then follow all the instructions 3 times. this is what i tried to
>> put in.
>>
>> class Robot:
>> pass
>>
>> def place_robot():
>> global robot
>> r1 = Robot()
>> r2 = Robot()
>> r3 = Robot()
>> robot = [r1,r2,r3]
>> robot.x=random_between(0,63)
>> robot.y=random_between(0,47)
>> draw_robot()
>> print robot.x
>>
>> i was under the assumption that the instruction
>> robot.x=random_between(0,63) would return a value 3 times for r1 r2 and r3,
>> but instead i get AttributeError: 'list' object has no attribute 'x'. so i
>> got no idea heh. i hope this makes sense, as im really new to programming.
>>
>
> I think what you want is:
>
> for r in robot:
> r.x = random_between(0,63)
> r.y = random_between(0,47)
> draw_robot()
> print r.x
>
> Now for the why:
> robot is a list of objects - you declared it such with robot = [r1, r2, r3]
> (incidentally you could just do robots = [Robot(), Robot(), Robot()] ), and
> lists don't have x y attributes, which you're trying to access. I presume
> you're really trying to access the x y attributes of your Robot() class,
> which is an entirely different object from your list.
>
> HTH,
> Wayne
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Ataulla SH

web:www.kring.com
personal blog:www.ataulla.objectis.net
KRING Technologies India Pvt. Ltd.
1st Floor, Tower B, Infinity Towers, DLF II, Gurgaon-122 002
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list question

2009-08-11 Thread Dave Angel

Wayne wrote:

On Tue, Aug 11, 2009 at 7:17 AM,  wrote:

  

 hi i am currently doing the 'livewires' python tutorial lesson 5. i am
making a little game that makes a few squares chase a circle around a little
grid. i can get the 1 square acting on 1 variable to come up, but the
tutorial now wants me to create a list of variables that act under the same
class.

this is what i have to make the 1 square appear (which works)(i have also
cut a lot of the program out to make this email smaller.)

class Robot:
pass

def place_robot():
global robot
robot = Robot()
robot.x=random_between(0,63)
robot.y=random_between(0,47)
draw_robot()
print robot.x

and i cant figure out what to write to make the variable 'robot' work as a
list, and then follow all the instructions 3 times. this is what i tried to
put in.

class Robot:
pass

def place_robot():
global robot
r1 = Robot()
r2 = Robot()
r3 = Robot()
robot = [r1,r2,r3]
robot.x=random_between(0,63)
robot.y=random_between(0,47)
draw_robot()
print robot.x

i was under the assumption that the instruction
robot.x=random_between(0,63) would return a value 3 times for r1 r2 and r3,
but instead i get AttributeError: 'list' object has no attribute 'x'. so i
got no idea heh. i hope this makes sense, as im really new to programming.




I think what you want is:

for r in robot:
r.x = random_between(0,63)
r.y = random_between(0,47)
draw_robot()
print r.x

Now for the why:
robot is a list of objects - you declared it such with robot = [r1, r2, r3]
(incidentally you could just do robots = [Robot(), Robot(), Robot()] ), and
lists don't have x y attributes, which you're trying to access. I presume
you're really trying to access the x y attributes of your Robot() class,
which is an entirely different object from your list.

HTH,
Wayne

  
This illustrates the danger of global variables.  The draw_robot() 
function probably accesses the global variable robot, which has now 
changed its meaning.  So probably it should be a method of the Robot 
class, in which case you'd use

r.draw_robot()

Alternatively, if it must be a function rather than a method, you should 
add a parameter to it, and call it as

   draw_robot(r)

If this were my code, I'd probably have created a new global variable  
robots, indicating that it's now a list.  And change the function 
place_robot() to place_robots().


DaveA

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


Re: [Tutor] easy way to populate a dict with functions

2009-08-11 Thread bob gailer

Albert-Jan Roskam wrote:

Hi Bob,

Sorry for the late reply, but thank you for your code. I still haven't 
completely wrappped my brain around decorator functions, but thanks to your 
reply at least now my frontal lobe is touching it. ;-)
  


Decorator functions:

def collect(func):
'a "decorator" that adds each function to the cmds list'
cmds.append((func.__name__, func))

# once collect is defined it may be used as a decorator:

@collect
def foo (a):
 return "foo" * a

# this means
# 1 - define foo
# 2 - run the following statement
foo = collect(foo)

# that
#  1 - appends foo to the cmds list
#  2 - returns None
#  3 - assigns None to foo (since we no longer need that name)

Admittedly this is not how decorators were intended to be used. The 
intention was to create some new function (presumably derived from foo 
in some useful way), return that and assign it to foo.



Re: the ordering of functions: I thought it mattered because the inspect module 
returns a list of two-tuples (in this case, a list of four two-tuples). 
Therefore, e.g. option #1 should always cause the same function to be run. But 
apparently I'm wrong here somewhere.
  
The only "wrong" is expecting order to be preserved, which dictionaries 
do not guarantee.


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


Re: [Tutor] To write data in two different fonts?

2009-08-11 Thread prasad rao
Hello
 I modified my code.But I am gettingmy my lines stripped of indentation.
What should I do to avoid it?Sorry if it is not about Python.




def sc(adir):
   import os,myfiles
   dest=open('C:/scripts.html','w')
   s=myfiles.myfiles(adir)
   dest.write('')
   for x in s:
  if os.path.isfile(x):
  sorce=open(x,'r')

  dest.write('')
  dest.write(x)
  dest.write('')


  for l in sorce:
   dest.write('')
   dest.write(l)
   dest.write('')
  sorce.close()
  else:pass
   dest.write('')
   dest.close()


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


Re: [Tutor] MySQLdb field type

2009-08-11 Thread Rick Pasotto
On Mon, Aug 10, 2009 at 07:22:03PM -0400, Kent Johnson wrote:
> 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?

I didn't realize there were different MySQLdb modules.

-- 
"Wit has truth in it; wise cracking is simply calisthenics with words."
-- Dorothy Parker
Rick Pasottor...@niof.nethttp://www.niof.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] To write data in two different fonts?

2009-08-11 Thread Dave Angel

prasad rao wrote:

Hello
 I modified my code.But I am gettingmy my lines stripped of indentation.
What should I do to avoid it?Sorry if it is not about Python.




def sc(adir):
   import os,myfiles
   dest=open('C:/scripts.html','w')
   s=myfiles.myfiles(adir)
   dest.write('')
   for x in s:
  if os.path.isfile(x):
  sorce=open(x,'r')

  dest.write('')
  dest.write(x)
  dest.write('')


  for l in sorce:
   dest.write('')
   dest.write(l)
   dest.write('')
  sorce.close()
  else:pass
   dest.write('')
   dest.close()



  
This question is about html.  You knew enough to put the html tags 
around it, and the p tags around each line.  But within a p tag, the 
element content is transparent to whitespace.   That's usually a good 
thing, as it means paragraphs automatically wordwrap according to the 
size and shape of the browser.  But you want the text here to be 
unformatted, preserving indents, and preserving embedded spaces.




The brute-force way might be to replace each space in "l" with
    which is a "nonbreaking space."  But I think you want the  
tag, which means the text is pre-formatted.  And you could put that 
around the whole sorce file, instead of doing  for each line.


See   http://www.w3schools.com/tags/tag_pre.asp

Incidentally, I think you ought to add  as well.  And maybe some 
other boilerplate to eliminate warnings in a browser.  You'll also get 
into trouble if any of the lines have "&" or "<" in them.


DaveA

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


Re: [Tutor] To write data in two different fonts?

2009-08-11 Thread Michael M Mason
Dave Angel wrote on 11 August 2009 at 16:42:-

> The brute-force way might be to replace each space in "l" with
>     which is a "nonbreaking space."  But I think you want the
 
> tag, which means the text is pre-formatted.  And you could put that 
> around the whole sorce file, instead of doing  for each line.

I think the  tag will work, but it will force the font to be
monospaced, overriding the "" tag that the OP has
included.

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


Re: [Tutor] droplet like behaviour in Python

2009-08-11 Thread Nick Raptis

pedro wrote:


#!/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.

Pete




Pedro, I'll reply to this message instead of the last one because, I 
actually tried the little script you have there, and it does work

I'm on Windows though.

Well, my version of your script is this:
-
import sys
for arg in sys.argv:
   print arg

raw_input()
-

The raw_input() at the end is what keeps the window open so I can see 
that something really happened before the window closed.
When I drop a file into my script, it prints two lines: The script 
filename and the filename of the file I dropped.

So I call it a win.

I don't know how it behaves in mac, but please try and tell. (Also put 
your usual #!/usr/bin/env python in there to work for you)


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


Re: [Tutor] easy way to populate a dict with functions

2009-08-11 Thread Kent Johnson
On Tue, Aug 11, 2009 at 10:22 AM, bob gailer wrote:

> Decorator functions:
>
> def collect(func):
> 'a "decorator" that adds each function to the cmds list'
> cmds.append((func.__name__, func))

Decorators must return a callable, add to the above:

  return func

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


Re: [Tutor] MySQLdb field type

2009-08-11 Thread Kent Johnson
On Tue, Aug 11, 2009 at 11:10 AM, Rick Pasotto wrote:

> I didn't realize there were different MySQLdb modules.

I didn't realize you had specified MySQLdb...sorry, I'm not being very
helpful. I don't know where to find that information for MySQLdb.

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


Re: [Tutor] droplet like behaviour in Python

2009-08-11 Thread Nick Raptis

For the Windows users out there:

A google search returned me this:
Make Python Scripts Droppable in Windows 



I checked my registry and the extension was there. That must be why my 
drop script works.
No idea how it got there though. FWIW, I have installed Python through 
the .msi installer.


PS: What I like is that the page I linked actually has my little test 
script in it :D

  I must be doing something right.

PS2: I guess I'm starting to deduce that the answer is 
platform/installation specific rather than python/script specific.

   That turns the question it to a whole new direction for me.

Nick

Nick Raptis wrote:

pedro wrote:


#!/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.

Pete




Pedro, I'll reply to this message instead of the last one because, I 
actually tried the little script you have there, and it does work

I'm on Windows though.

Well, my version of your script is this:
-
import sys
for arg in sys.argv:
   print arg

raw_input()
-

The raw_input() at the end is what keeps the window open so I can see 
that something really happened before the window closed.
When I drop a file into my script, it prints two lines: The script 
filename and the filename of the file I dropped.

So I call it a win.

I don't know how it behaves in mac, but please try and tell. (Also put 
your usual #!/usr/bin/env python in there to work for you)


Nick
___
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] droplet like behaviour in Python

2009-08-11 Thread Wayne
On Tue, Aug 11, 2009 at 4:49 PM, Nick Raptis  wrote:

>
> PS2: I guess I'm starting to deduce that the answer is
> platform/installation specific rather than python/script specific.
>   That turns the question it to a whole new direction for me.


It's probably even more than that - my guess is it's very dependent on the
window manager (or whatever happens to produce your icons, which is usually
the WM). I don't know how different the various WM's are on linux, but I
know there are several to choose from. Having this cross-platform may not be
the easiest thing - you'd probably have to use an os module call to check
the system to determine the proper course of action or something otherwise
technically advanced.

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


[Tutor] string.title(): correct?

2009-08-11 Thread Allen Fowler

Hello,

"He's a great guy".title()

Gives me:
 
"He'S A Great Guy"


I expected:

"He's A Great Guy"

Did i miss something here?

Thank you,
:)


  

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


Re: [Tutor] To write data in two different fonts?

2009-08-11 Thread Dave Angel

Michael M Mason wrote:

Dave Angel wrote on 11 August 2009 at 16:42:-

  
The brute-force way might be to replace each space in "l" with
    which is a "nonbreaking space."  But I think you want the

 
  
tag, which means the text is pre-formatted.  And you could put that 
around the whole sorce file, instead of doing  for each line.



I think the  tag will work, but it will force the font to be
monospaced, overriding the "" tag that the OP has
included.

  
That font= syntax was probably bogus.  But in any case, I meant to put 
the  around each sorce file expansion, not around the whole 
destination file, and implied that the  and  lines go away.


Something like:

 dest.write('
 dest.write(x)
 dest.write('')

 dest.write("")
 for l in sorce:
  dest.write(l)
 sorce.close()
 dest.write("")


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


Re: [Tutor] easy way to populate a dict with functions

2009-08-11 Thread bob gailer

Kent Johnson wrote:

On Tue, Aug 11, 2009 at 10:22 AM, bob gailer wrote:

  

Decorator functions:

def collect(func):
'a "decorator" that adds each function to the cmds list'
cmds.append((func.__name__, func))



Decorators must return a callable


The docs indeed say that, but the interpreter does not enforce it. My 
example works as I designed it.



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


Re: [Tutor] string.title(): correct?

2009-08-11 Thread bob gailer

Allen Fowler wrote:

Hello,

"He's a great guy".title()

Gives me:
 
"He'S A Great Guy"



I expected:

"He's A Great Guy"

Did i miss something here?
  


The docs state:

"title( ) - Return a titlecased version of the string: words start with 
uppercase characters, all remaining cased characters are lowercase."


It depends on the definition of "word".


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


Re: [Tutor] To write data in two different fonts?

2009-08-11 Thread prasad rao
> > But I think you want the  tag, which means the text is
> pre-formatted.  And you could >put that around the whole sorce file, instead
> of doing  for each line.
>
> >See   http://www.w3schools.com/tags/tag_pre.asp


Thank you Dave.
I put in tag  and it worked. But at one particular line in a module
the font changed colour.After that all the lines are in blue colour and
under lined.
I removed that module from the directory and now it is working well.I could
not
figure out why the change of colour of font took place.

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


[Tutor] creating an exe

2009-08-11 Thread proportional
hi, thanks to all that helped with my list question yesterday. i have now 
finished my program the way i want it. is there a way to compile my program so 
that people without python can see what i have made?___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor