Re: [Tutor] Selecting a browser

2007-12-03 Thread Simone
Ricardo Aráoz ha scritto:


>> ff = webbrowser.get("S:/FirefoxPortable/FirefoxPortable.exe %s &")
> That did it, but as I told Kent :
> 
> ff.open('http://www.google.com')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "E:\Python25\lib\webbrowser.py", line 168, in open
> p = subprocess.Popen(cmdline, close_fds=True)
>   File "E:\Python25\lib\subprocess.py", line 551, in __init__
> raise ValueError("close_fds is not supported on Windows "
> ValueError: close_fds is not supported on Windows platforms

I think the problem is in '&' at the end of the command line.

The '&' is used on Linux/Unix system to start processes in a independent 
thread.

Remove it and it works!

Simone
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python CLI parser

2007-12-28 Thread Simone
bob gailer ha scritto:

>> could you have a short review of my CLI package.
> .bz2???  What does that extension mean? (For us Windows folk). Or could 
> you attach a simple zip file?

.bz2 is an archive compressed with the bzip2 compression program. If 
you're on Windows, consider to use 7zip for managing compressed archive 
(www.7zip.org): open source & free (as in freedom) and better, IMHO, 
than WinZip.

Simone
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] preventing SQL injection

2008-01-11 Thread Simone
johnf ha scritto:

> But the above does not work when I use variables instead of strings as in
> 
> tempCursor.execute ( "Select pg_get_serial_sequence ( %s, %s ) as  
> seq", ( tableName, fieldName ) )
> 
> So how am I suppose to prevent SQL injections?

Try tu use '?' instead of %s, like this:

tempCursor.execute ( "Select pg_get_serial_sequence ( ?, ? ) as seq", ( 
tableName, fieldName ) )

For further information see PEP 249 
(http://www.python.org/dev/peps/pep-0249/)

HTH!

Simone
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] my first project: a multiplication trainer

2008-03-18 Thread Simone
Guba ha scritto:

> I was unable to find information on tuple(). (The Python help function
> was rather conservative in its output, Google not helpful).
> What exactly is the use of tuple(q) here, and why does not a simple q
> instead of tuple(q) do? The latter would have been my intuitive
> expectation...

The print statement "%dx%d = " needs a tuple of arguments. The tuple() 
command, that converts a list or a set of values in a tuple of values, 
prevent that error (for example, if the list of values is a list o of 
list, the print statemnte returns the error "TypeError: in argument 
reguired").

For example:

 >>>a = [[1, 2], [3, 4]] # a is a list of lists with 2 values

 >>>type(a[0])


 >>>type(tuple(a[0]))


Or:

 >>>a = [(1, 2), (3, 4)] # a is a list of tuples with 2 values

 >>>type(a[0])



> The other thing I have on my mind is this: how could I have the program
> ask the math questions not horizontally but vertically? An example:
> 
>  4
> x7
> =

Simply insert a \n in the print statement, like this:

print "%d\nx%d\n = "

Simone
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 

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


Re: [Tutor] SQLite LIKE question

2008-04-11 Thread Simone
Dinesh B Vadhia ha scritto:

> The second problem is that I'm using the LIKE operator to match a 
> pattern against a string but am getting garbage results.  For example, 
> looking for the characters q='dog' in each string the SELECT statement 
> is as follows:
>  
> for row in con.execute("SELECT  FROM  WHERE  LIKE 
> '%q%' limit 25"):
> print row
>  
> This doesn't work and I've tried other combinations without luck!  Any 
> thoughts on the correct syntax for the LIKE?

In Python the symbol '%' in a string is a special char: you use it, for 
instance, to place a variable inside a string.

The command you need is something like this:

query = "SELECT  FROM  WHERE  LIKE '%s'" % q
for row in con.execute(query):
print row

where q is your variable and %s tells Python that the q variable has to 
be converted in a string during the string valorization.

If you want that q contains the symbol '%', you have to escape it by 
inserting 2 '%'.

In your example, q have to be 'dog%%' instead of 'dog%'.

However, as Alan said, the method with the question mark to construct 
the query is more safe than this.

Hope that helps,
Simone
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 

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


Re: [Tutor] Empty list validation

2008-06-09 Thread simone

[EMAIL PROTECTED] ha scritto:

Sorry if this is a basic question, but how do I check if list is empty 
or not and return True or False ;)


Normally, in Python, there are these evaluation:

1) True == 1
2) False == 0
3) Empty or have not value == False == 0
4) Not empty or have value == True == 1

So, consider this example:

>>> def isEmpty(l):
if l:
print "The list is NOT empty!"
else:
print "The list is empty!"


>>> list = []
>>> isEmpty(list)
The list is empty!
>>> list = ['hi']
>>> isEmpty(list)
The list is NOT empty!
>>>

HTH,
Simone
Chiacchiera con i tuoi amici in tempo reale! 
http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 


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


Re: [Tutor] error message with multiple inheritance

2008-06-10 Thread simone

Christopher Spears ha scritto:


I've been working out of Core Python Programming (2nd Edition).  Here is an 
example demonstrating multiple inheritance.


class A(object):

... pass
...

class B(A):

... pass
...

class C(B):

... pass
...

class D(A, B):

... pass
...
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases B, A

What does this error message mean?  The example worked in the book.  I checked 
in the docs and could not find anything.


http://www.python.org/download/releases/2.3/mro/
Chiacchiera con i tuoi amici in tempo reale! 
http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 


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


Re: [Tutor] Any Italian speakers?

2008-08-05 Thread simone

Alan Gauld ha scritto:


---
voglio chiderti solo 1 cosa ... ma secondo te qualle e il miglior 
programma X programmare???

grazie ...

da Cristian
-


Literally:

---
"I want to ask you only one thing... what's in your opinion the best 
program to program?"


from Cristian
---

--
Simone


Chiacchiera con i tuoi amici in tempo reale! 
http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 


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


Re: [Tutor] renumbering a sequence

2008-08-26 Thread simone

Christopher Spears ha scritto:


As you can see, the only part I haven't figured out is the actual renumbering.  
Can't figure out how to do the following:
0017 convert to -> 0001
0018 convert to -> 0002
0019 convert to -> 0003
etc.

Any hints?  Thanks.


IMHO, you can renumber everything without testing the right order. An 
example:


for progress, file_name in enumerate(ordered_list):
   frame, num, ext = file_name.split('.')
   print "%s.%s.%s" % (frame, str(progress).zfill(4), ext)

And you will have what you want (if I understand right...).

--
Simone
Chiacchiera con i tuoi amici in tempo reale! 
http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 


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


Re: [Tutor] Where Does the DOS Window Come From?

2008-09-24 Thread simone

Wayne Watson ha scritto:

I'm looking at a GUI application that I hope to modify in the next few 
weeks. When it's executed the expected GUI appears along with a DOS 
window. Occasionally, I think, I've seen something put in the DOS 
window. How do I stop it from appearing and how do I find why it's used?


If you don't want the DOS window, you can change the extension of the 
file to .pyw instead of .py, but in this case you will not see the 
messages printed by the print statement.


--
Simone
Chiacchiera con i tuoi amici in tempo reale! 
http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 


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