Re: getting source code line of error?

2021-11-20 Thread Paolo G. Cantore

Am 20.11.21 um 20:15 schrieb Ulli Horlacher:

Stefan Ram  wrote:

r...@zedat.fu-berlin.de (Stefan Ram) writes:

except Exception as inst:
print( traceback.format_exc() )


   More to the point of getting the line number:


As I wrote in my initial posting:
I already have the line number. I am looking for the source code line!

So far I use:

   m = re.search(r'\n\s*(.+)\n.*\n$',traceback.format_exc())
   if m: print('%s %s' % (prefix,m.group(1)))


Stefan Ram's solution missed only the line content. Here it is.


import sys
import traceback

try:
1/0
except ZeroDivisionError as exception:
tr = traceback.TracebackException.from_exception( exception )
x = tr.stack[0]
print("Exception %s in line %s: %s" % (exception, x.lineno, x.line))


The traceback object does not only contain the lineno but also the 
content of the offending line.


--
Paolo
--
https://mail.python.org/mailman/listinfo/python-list


Delegating to part of a subgenerator

2020-12-19 Thread Paolo Lammens
Dear all,

I've been struggling with the following problem, and I thought maybe there
is someone here in python-list who could shine some light on this.

Suppose we have a generator function `subgen`, and we want to wrap this in
another generator function, `gen`. For clarity, these are "full"
generators, i.e. they make use of .send, .throw, .close, etc. The purpose
of `gen` is to intercept the first value yielded by `subgen`, transforming
it in some form, and forwarding it on to the caller; after that, it should
just delegate to the rest of the generator iterator with `yield from`.

The problem is, the semantics of `yield from` expect a "fresh" generator
iterator, not a partially consumed generator. Indeed, the first value that
`yield from` will send to the iterator will be `None`, to start the
execution of the generator. But in this case we have already started the
generator, and to continue its execution we should really send whatever we
received after yielding the first value. However there's no way to specify
this with the `yield from` syntax.

A solution would be to re-implement the semantics of `yield from`, but with
an optional starting value (other than None) that will be sent to the
iterator as the initial value. However this means, as I said,
re-implementing the whole of `yield from`, i.e. handling .send(), .throw(),
.close(), etc., which is not ideal. So that would not be a good solution.
Am I asking for the impossible?

More details and an example in my original stackoverflow question:
https://stackoverflow.com/q/65369447/6117426

Best,
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to create an Excel app that runs Python?

2020-03-28 Thread Paolo G. Cantore

Am 25.03.20 um 15:21 schrieb farayao...@gmail.com:



Hello Paolo,

Thanks for your reply, indeed now I'm thinking on building a web app, do you 
have any suggestions for this? I am thinking of using Tkinter, the method that 
you describe using HTML is also using Javascript?

Kind Regards
Felipe


Hello Felipe,

only bare HTML is needed, no Tkinter, no JavaScript.

Have a look in the attached prototype. For use in your Intranet some 
definitions have to be done by your IT people and the script run mode 
has to be changed too.


So far it is tested on my machine (Linux, Python3.6). The only 
dependancy is bottle.


Maybe it's suited for your needs.

Kind Regards
Paolo
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to create an Excel app that runs Python?

2020-03-24 Thread Paolo G. Cantore



On Tue, Mar 24, 2020, 4:45 PM  wrote:


I have the following scenario:

I have created lots of python files that I use to calculate a Cashflow
model, when I run these files I get a beautiful pandas DataFrame that
contains my final model. My mission is to show this table to the rest of
the company in a friendly format ("Excel") and they need to be able to
generate this table themselves from Excel, using the Python script I
created ("the idea is that they open an excel file that has some type of
dashboard and a form that they need to fill in, once they fill it in and
press "Go" or "Run" or something like that, these parameters will be sent
to the Python script to generate this final pandas DataFrame. Finally this
DataFrame needs to be displayed/pasted in the Excel sheet that they
initially opened)


The problems:

The company needs to be able to run this model, but the users, apart from
me, use Excel and they can't open up a Jupyter notebook or VSC to run the
code. They can't even install Python on their machines (or at least that is
not ideal)


My Attempts:

I am currently using "xlwings" to run Python within Excel, although it
requires that the user has Python and xlwings installed and has added the
xlwings "Addin", which is not an ideal solution at all.

I am thinking about using Dash, I don't know if it is what I need since I
haven't looked into it that much yet (I have been trying to make it work on
xlwings first)



If you have any suggestions on how to do this, I would really appreciate
that.

Thank you
--
https://mail.python.org/mailman/listinfo/python-list


The scenario you describe should be fulfilled by a web application.

I'm sure your users are also able to use a browser, not only Excel.

The HTML forms management offers the GUI capabilities to enter the 
parameters. The processing steps could be as follows:


1. Enter the url for the application in question and display the form.
2. Enter the needed data in the form.
3. Process the data (with lots of your python scripts) and show the 
result in the browser.
4. If all is ok, download the data sheet in Excel format (using 
DataFrame.to_excel)


--
https://mail.python.org/mailman/listinfo/python-list


Re: Python help needed

2019-08-08 Thread Paolo G. Cantore

Am 08.08.19 um 01:18 schrieb MRAB:

On 2019-08-07 21:36, Kuyateh Yankz wrote:
#trying to write a function that takes a list value as an argument and 
returns a string with all the items separated by a comma and a space, 
with and inserted before the last item. For example, passing the 
previous spam list to the function would return 'apples, bananas, 
tofu, and cats'. But your function should be able to work with any 
list value passed to it.


def myList(aParameter): #defined
 finalList = []
 for i in range(len(aParameter)-1): #targeting the last item in 
the list
   finalList.append('and '+ aParameter[-1]) #Removes the last item 
in the list, append the last item with THE and put it back, then put 
it into the FINAL LIST FUNCTION.

 return finalList
spam = ['apples', 'bananas', 'tofu', 'cats']
print(myList(spam))

#Got up to this point, still couldn't get rid of the '' around the 
items and the []. I tried (','.join()) but could not get there.

#Am I on the wrong path or there's a quick fix here?
https://pastebin.com/JCXisAuz

There's a nice way of doing it using str.join. However, you do need to 
special-case when there's only 1 item.


Start with a list:

 >>> spam = ['apples', 'bananas', 'tofu', 'cats']

The last item will be have an 'and', so let's remove that for the moment:

 >>> spam[ : -1]
['apples', 'bananas', 'tofu']

Join these items together with ', ':

 >>> ', '.join(spam[ : -1])
'apples, bananas, tofu'

Now for the last item:

 >>> ', '.join(spam[ : -1]) + ' and ' + spam[-1]
'apples, bananas, tofu and cats'

For the special case, when len(spam) == 1, just return spam[0].


I think the special case treatment could be avoided.

First: Join all items with ' and '
Second: Replace all ' and ' with ', ' except the last

>>> spam = ['apples', 'bananas', 'tofu', 'cats']
>>> s = " and ".join(spam)
>>> s.replace(" and ", ", ", len(spam) - 2)  # except the last
'apples, bananas, tofu and cats'

Or as a one liner:
" and ".join(spam).replace(" and ", ", ", len(spam) - 2)

It works also for a single item list:
>>> spam = ['apples']
'apples'
--
https://mail.python.org/mailman/listinfo/python-list


scrivere file

2017-02-12 Thread Paolo
Buonasera, è da un pò che sto cercando come esercizio di scrivere un 
file al contrario.
Mi spiego meglio ho un file con N righe e vorrei scriverne un altro con 
gli stessi dati ma la 1° riga deve diventare l' ultima.
Es. file di partenza
riga1
riga2
riga3
riga4

file riscritto

riga4
riga3
riga2
riga1

Grazie anticipamente per i consigli

-- 
Paolo
-- 
https://mail.python.org/mailman/listinfo/python-list


error installing pyton

2014-12-30 Thread Paolo Cavalletti
Whwn the  installe starts it goes to crsh afere asking if i like the insllation 
for une o alla users of the pc
in attach the report error
Thanks
Paolo-- 
https://mail.python.org/mailman/listinfo/python-list


focus on jtextfield

2012-09-04 Thread Paolo
how do I know if a JTextField has the focus? 
thank to all
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [NUMPY] "ValueError: total size of new array must be unchanged" just on Windows

2011-10-14 Thread Paolo Zaffino
Nobody can help me?



2011/10/12 Paolo Zaffino 

> I wrote a function thaht works on a 3D matrix.
> As first thing I have an array and I want reshape it into a 3D matrix (for
> further manipulations).
> For this reason I wrote in a row:
>
> matrix=matrix.reshape(a, b, c).T
>
> It work fine on GNU/Linux and Mac OS but not on Windows.
> In Windows I get this error:
>
> matrix=matrix.reshape(a, b, c).T
>
> ValueError: total size of new array must be unchanged
>
> Thank you.
>
>
>
>
> 2011/10/11 David Robinow 
>
>> 2011/10/11 Paolo Zaffino :
>> > Nobody can help me?
>>  Nope, not unless you post some code. Your problem description is too
>> vague.
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [NUMPY] "ValueError: total size of new array must be unchanged" just on Windows

2011-10-12 Thread Paolo Zaffino
I wrote a function thaht works on a 3D matrix.
As first thing I have an array and I want reshape it into a 3D matrix (for
further manipulations).
For this reason I wrote in a row:

matrix=matrix.reshape(a, b, c).T

It work fine on GNU/Linux and Mac OS but not on Windows.
In Windows I get this error:

matrix=matrix.reshape(a, b, c).T

ValueError: total size of new array must be unchanged

Thank you.



2011/10/11 David Robinow 

> 2011/10/11 Paolo Zaffino :
> > Nobody can help me?
>  Nope, not unless you post some code. Your problem description is too
> vague.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [NUMPY] "ValueError: total size of new array must be unchanged" just on Windows

2011-10-11 Thread Paolo Zaffino
Nobody can help me?




2011/10/10 Paolo Zaffino 

> On Mac OS there is numpy 1.2.1, on Fedora 14 64bits numpy 1.4.1 and on
> Ubuntu 10.04 64bits numpy 1.3.0.
> On these platforms my function runs without problems.
> Just on Windows it doesn't works.
>
>
>
> 2011/10/9 Yaşar Arabacı 
>
>> I don't know about your problem, but did you compare numpy versions in
>> windows and other platforms? You may have newer/older version in Windows.
>> Otherwise, it looks like a platform spesific bug to me.
>>
>> 2011/10/9 Paolo Zaffino 
>>
>>>  Hello,
>>> I wrote a function that works on a numpy matrix and it works fine on
>>> Mac OS and GNU/Linux (I didn't test it on python 3)
>>> Now I have a problem with numpy: the same python file doesn't work on
>>> Windows (Windows xp, python 2.7 and numpy 2.6.1).
>>> I get this error:
>>>
>>> matrix=matrix.reshape(a, b, c)
>>> ValueError: total size of new array must be unchanged
>>>
>>> Why? Do anyone have an idea about this?
>>> Thank you very much.
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>
>>
>>
>> --
>> http://yasar.serveblog.net/
>>
>>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [NUMPY] "ValueError: total size of new array must be unchanged" just on Windows

2011-10-10 Thread Paolo Zaffino
On Mac OS there is numpy 1.2.1, on Fedora 14 64bits numpy 1.4.1 and on
Ubuntu 10.04 64bits numpy 1.3.0.
On these platforms my function runs without problems.
Just on Windows it doesn't works.


2011/10/9 Yaşar Arabacı 

> I don't know about your problem, but did you compare numpy versions in
> windows and other platforms? You may have newer/older version in Windows.
> Otherwise, it looks like a platform spesific bug to me.
>
> 2011/10/9 Paolo Zaffino 
>
>> Hello,
>> I wrote a function that works on a numpy matrix and it works fine on
>> Mac OS and GNU/Linux (I didn't test it on python 3)
>> Now I have a problem with numpy: the same python file doesn't work on
>> Windows (Windows xp, python 2.7 and numpy 2.6.1).
>> I get this error:
>>
>> matrix=matrix.reshape(a, b, c)
>> ValueError: total size of new array must be unchanged
>>
>> Why? Do anyone have an idea about this?
>> Thank you very much.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
>
> --
> http://yasar.serveblog.net/
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


[NUMPY] "ValueError: total size of new array must be unchanged" just on Windows

2011-10-09 Thread Paolo Zaffino
Hello,
I wrote a function that works on a numpy matrix and it works fine on
Mac OS and GNU/Linux (I didn't test it on python 3)
Now I have a problem with numpy: the same python file doesn't work on
Windows (Windows xp, python 2.7 and numpy 2.6.1).
I get this error:

matrix=matrix.reshape(a, b, c)
ValueError: total size of new array must be unchanged

Why? Do anyone have an idea about this?
Thank you very much.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: argparse and default for FileType

2011-04-12 Thread Paolo Elvati
> Open up a bug report on the Python bug tracker and assign it to the user
> "bethard", who is the author of argparse. He's usually pretty responsive.

Thank you for the answer, I will.



Paolo
-- 
http://mail.python.org/mailman/listinfo/python-list


argparse and default for FileType

2011-04-08 Thread Paolo Elvati
Hi,

I noticed a "strange" behavior of argparse.
When running a simple code like the following:

import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
  "-o",
  default = 'fake',
  dest = 'OutputFile',
  type = argparse.FileType('w')
 )
args = parser.parse_args()

I noticed that the default file (fake) is created every time I run the
code, even when I explicitly set the -o flag, in which case it will
produce both files.
My goal instead is to erite the default file ONLY if the flag is not specified.
For the moment, I solved it simply by removing the "default=fake" and
adding the "required=True" keyword, but I was wondering what is the
correct way of doing it (or if it is simply a bug).

Thank you,

Paolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turn-based game - experimental economics

2009-09-11 Thread Paolo Crosetto
In data sabato 05 settembre 2009 21:47:41, Dennis Lee Bieber ha scritto:

> Much better to just send the token TO the active client (which is
> responsible for returning it at the end of its turn processing) 

Dennis,

I am finally getting my head round this problem. I do have a further question, 
though.

I am using XMLRPC as server. It is quite convenient since it handles all low-
level network stuff for me. On the other hand, though, it seems I cannot make 
the server actually _send_ anything to the clients; it just sits there and 
waits for calls.
This is rather inconvenient for me, as every time I need to send the clients 
some information (eg, the state of the game) I have to formulate the problem 
as a specific call from each client. This can indeed be done quite easily, but 
the end result is a staggering amount of calls to the server, and high cpu 
usage - this might as well slow down the network in the lab, I guess.

If you look at the pseudocode you sent me - and I implemented - you see, on 
the clients side, where the --> are, that a call to update is made over 
and over again.

-=-=-=-=-=- "Display"

connect to "game"
ACTIVE = False
while True:
get game data---> *
update console display  ---> *
ACTIVE = game data == active token
if ACTIVE:
get user input
if user input == EndTurn:
ACTIVE = False
send user input
if user input == QUIT:
break
disconnect from "game"


Is there any way of telling XMLRPC 'send this and this to all clients 
connected'?
Or should I use another server-side technology? I have no much experience in 
writing network programs - this is my first - and I'd rather not go into 
complicated stuff.

Thanks!
-- 
Paolo Crosetto
-
PhD Student in Economics
DEAS - Department of Economics - University of Milan
-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turn-based game - experimental economics

2009-09-06 Thread Paolo Crosetto
Dennis,

thanks.

>   Do the clients have to do anything between turns? If not, the
> simplest thing is to just have these clients block on a read request
> waiting for data to be returned from the server.


the only thing that the clients do is receiving information on the action of 
other players, and updating some player-related and state-of-the-world related 
statistics. 
> 
>   {BTW: I think the term you're looking for is "console" or "command
> line" client ; after all -- stdout is just and I/O stream, and bash
> is just a shell interpreter}


thanks, exactly. My plan is to have a GUI in the end, but in the meantime - 
for testing - it is important for me to have a working version and I was 
planning to address the GUI issue later.

>   The only controlling aspect of your users is the initial connection
> to the "game". Once connected, the users are at the mercy of the "game"
> to notify them that it is time for them to enter instructions (you don't
> describe enough detail to determine if a "turn" is a single transaction,
> or could consist of multiple transactions [you mentioned "buying
> letters" along with playing letters to extend words; can both take place
> in one turn?])

This is a good idea. Details: for every turn, the player performs three 
operations: buy(not buy); create(a word, an extension, nothing); copyright(or 
not), then passes. Other players do not really need to be notified in real 
time, can as well be notified at the end of the turn. 

To give some more details, basically the game works as follows:
each turn, players buy, produce, decide on Intellectual property of their 
creation. The words created pass through a spellchecker and other basic checks 
(does the player really own the letters he's using, etc...) and then is added 
to a public wordlist; copyrighted words entitle the owner with royalties and 
copylefted words do not. Every time a player extends a copyrighted word there 
is a flow of royalties to be allocated.

> 
> -=-=-=-=- "Game"
> ConnectionThread:
>   while True:
>   accept connection
>   send world state to new display/player
>   add connection to connection list   #lock
> 
> Main:
>   start connection thread
>   active player = 0
>   while True:
>   if len(connection list):
>   send ACTIVE token to connection list [active player]
>   while True:
>   get player response
>   if response == QUIT:
>   del connection list [active player] 
> #lock
>   update world state
>   for p in connection list:   
> #lock
>   send world update to p
>   if response == EndTurn: break
>   active player = (active player + 1) % len(connection 
> list)
>   else:
>   sleep(1)#no players connected, so sleep before 
> repeating
> 
> (the #lock indicate operations that may need to be protected by using a
> lock object)
> 
> 
> -=-=-=-=-=- "Display"
> 
> connect to "game"
> ACTIVE = False
> while True:
>   get game data
>   update console display
>   ACTIVE = game data == active token
>   if ACTIVE:
>   get user input
>   if user input == EndTurn:
>   ACTIVE = False
>   send user input
>   if user input == QUIT:
>   break
> disconnect from "game"
> 

Thanks for this pseudocode - helpful in many ways. The only  reason I had to 
structure the game as a one server-many clients was that I wanted to 
centralize the functions related to computing the payoffs etc in the server. I 
think this can be done in your architecture too.

P

-- 
Paolo Crosetto
-
PhD Student in Economics
DEAS - Department of Economics - University of Milan
-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Turn-based game - experimental economics

2009-09-05 Thread Paolo Crosetto
Dear Terry, 

thanks.
> 
> As I understand your description, the server and each client will be a
> separate process on a separate machine (once deployed), so threads do
> not seem applicable. (For development, you can use separate processes on
> one machine communicating through sockets just as if they were on
> multiple machines.) 

Exactly. And this is exactly how I do it now. I have a process for the server, 
and process for the client (I succeeded in having it working with one client). 
I use XMLRPC to setup the server and make calls from the client.

> As I understand select, it is for select *any*
> available client input, not just one in particular. I believe the
> standard solution is to define a 'turn token' and write the clients so
> that they only do 'turn' activities when and only when they have that
> token.

This is similar to what bouncynic suggested. I was thinking of having a status 
global variable in the server that register whose turn it is [eg a list of N 
zeroes for N players] and ask the client to read that variable and act only 
when their own element in the list turns to one, white otherwise.

Does this make sense?

> I presume you do not need to worry about players trying to cheat
> by rewriting the client.

No, not really :)

I have one more question, then:

how do I make the client stay alive during the waiting period? Let me explain 
with rubbish pseudocode. Right now the code for handling turns, with status 
held on alist on the server, would be:

client:

if server.getStatus[i]==1:
...play all the actions in one's turn...
server.changeStatus[i] #changes to zero the global status var
server.passTurn #the last action for client i is to set to 1 the 
triggervar 
for client i+1

else:
wait

Now, my question is: how do I implement 'wait' without making the client exit? 
With gui-based clients I guess it is done with mainloop() keeping the app 
alive until something closes it; how do I achieve that with stdout (bash) 
clients?

Sorry for the not-so-much related question, and thanks for your suggestions.

-- 
Paolo Crosetto
-
PhD Student in Economics
DEAS - Department of Economics - University of Milan
-
-- 
http://mail.python.org/mailman/listinfo/python-list


Turn-based game - experimental economics

2009-09-05 Thread Paolo Crosetto
Dear all,

I am writing an application in Python for an experiment in Experimental 
Economics.

For those who do not know what this is: experimental economics uses 
controlled, computerised lab experiments with real subjects, putting the 
subject in a game mimicking the situation of interest and collecting 
behavioural data about choices made.

Hence, experiments involve the use of a multi-client architecture with one 
server, and are sort of online games, with actions taken by clients and 
computation, data collection, etc... handled by servers.

I chose to use Python because I needed something flexible, powerful and easy - 
I am a beginner programmer.

My game is a sort of scrabble, with palyers buying letters and producing words 
or extending existing words. I use a pipe to ispell -a for spellcheck, XMLRPC 
for the server-client infrastructure, and have developed all the rules of the 
game as server functions, called by a client. States of players and of words 
created are stored in instances of two basic classes, Player and Word, on the 
server side.

The problem I now face is to organise turns. Players, as in Scrabble, will 
play in turns. So far I have developed the server and ONE client, and cannot 
get my head round to - nor find many examples of - how to simply develop a 
turn-based interaction.
I basically need the server to freeze in writing all the clients while client 
i is playing, then when i is over passing the turn to i+1; clients are still 
accessible by the server at any time (the payoff of a player changes even as 
she is not playing, by royalties collected from other players extending her 
words).

In another thread (about a battleship game) I found two possible leads to a 
solution:
1. using 'select'.
2. using threads.

But in both cases I could not find any clear documentation on how to do this. 
The 'select' road was said to be the easiest, but I found no further hints.

Does anyone have any hints?

thanks!

-- 
Paolo Crosetto
-
PhD Student in Economics
DEAS - Department of Economics - University of Milan
-
-- 
http://mail.python.org/mailman/listinfo/python-list


Embedding python a la erb

2008-06-04 Thread PAolo
hello,

is there any other tool for embedding python as erb (for ruby) or empy
do. In particular I am not too happy about the way loops are made

@[for i in range(10)]@
xxx @(i)
@[end for]

which is different form the way other code is delimited

@{print 1+1}

I think in PHP there is not this difference and maybe in JSP too. Is
there any simple way to use PSP for that purpose?

Thanks
Paolo
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python is slow

2008-05-24 Thread Paolo Victor
I love it when a troll tries to make his/hers/its point with a vague,
biased assumption:

"I mean, it's not that slow - wait, I guess it's slower, because I...
I think so! Yeah! It's slow! At least it feels like it..."

It's all about choosing the right tool. If you think Python doesn't
suit your needs, you really should look for something that does,
instead of wasting your (and our) time with "guesses" and "feelings".

Research/develop/execute a benchmark. Gather and analyze relevant
data. Make a real contribution.

Peace,
Paolo

On May 24, 3:12 am, Torsten Bronger <[EMAIL PROTECTED]>
wrote:
> Hallöchen!
>
> cm_gui writes:
> > [...]
>
> > if python is such a good programming/scripting language,
> > why can't they build a faster interpreter/compiler engine?
> > and beat php and zend.
> > to the python team, rebuild your interpreter!
>
> > torontolife.com is slow.
>
> For me, torontolife.com is exactly as fast as Wikipedia.
>
> Tschö,
> Torsten.
>
> --
> Torsten Bronger, aquisgrana, europa vetus
>   Jabber ID: [EMAIL PROTECTED]
>(Seehttp://ime.webhop.orgfor further contact info.)

--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrong exist status for os.system, os.poepen, etc.

2007-03-06 Thread PAolo
On 6 Mar, 16:51, "Paul Boddie" <[EMAIL PROTECTED]> wrote:
> On 6 Mar, 16:39, "Paolo Pantaleo" <[EMAIL PROTECTED]> wrote:
>
>
>
> > The os.system() (but all the other funciont with similar behavior) reports
> > wrong exit status. I can reproduce the bug in the following way
>
> I think you should look at some previous threads related to this
> (obtained by searching Google Groups for "os.system exit status
> code"):
>
> "grabbing return codes from os.system() 
> call"http://groups.google.com/group/comp.lang.python/browse_frm/thread/efe...
>
> "please help me understand os.system() 
> result"http://groups.google.com/group/comp.lang.python/browse_frm/thread/4a9...
>
> "os.system() << 8 
> ?"http://groups.google.com/group/comp.lang.python/browse_frm/thread/f12...
>
> In short, the returned code is actually a combination of two values,
> and you need to extract the expected status code by shifting the
> result 8 bits to the right. It may actually be more complicated than
> that, but the man page for system ("man 3 system") explains this in
> more detail.
>
> Paul

Sorry, for the mistake, I just missed the words "encoded in the format
specified for wait()" in the documentation of popen()

Thnx for the immediate answer
PAolo

-- 
http://mail.python.org/mailman/listinfo/python-list


Wrong exist status for os.system, os.poepen, etc.

2007-03-06 Thread Paolo Pantaleo
Subject: python2.4: Wrong exist status for os.system, os.poepen, etc.
Package: python2.4
Version: 2.4.4-2
Severity: normal



-- System Information:
Debian Release: 4.0
  APT prefers testing
  APT policy: (800, 'testing'), (70, 'stable'), (60, 'unstable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-3-k7
Locale: LANG=it_IT.UTF-8, LC_CTYPE=it_IT.UTF-8 (charmap=UTF-8)

I send this to python-list also, so someone can tell if he/she can
(not) reproduce
the same behavior

The os.system() (but all the other funciont with similar behavior) reports
wrong exit status. I can reproduce the bug in the following way

create /tmp/x.c:

#include 

int main(void){
exit(20);
}

$ cd /tmp
$ make x

$./x
$echo $?
20

$ python

give the following commands:

>>> import os
>>> os.system("/tmp/x")
5120

the same for

>>> x=os.popen("/tmp/x")
>>> x.read()
''
>>> x.close()
5120


Greetings
PAolo



Versions of packages python2.4 depends on:
ii  libbz2-1.0  1.0.3-6  high-quality block-sorting file co
ii  libc6   2.3.6.ds1-10 GNU C Library: Shared libraries
ii  libdb4.44.4.20-8 Berkeley v4.4 Database Libraries [
ii  libncursesw55.5-5Shared libraries for terminal hand
ii  libreadline55.2-2GNU readline and history libraries
ii  libssl0.9.8 0.9.8c-4 SSL shared libraries
ii  mime-support3.39-1   MIME files 'mime.types' & 'mailcap
ii  python2.4-minimal   2.4.4-2  A minimal subset of the Python lan

python2.4 recommends no packages.

-- no debconf information
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading csv files using SQL

2007-03-01 Thread Pablo was Paolo
Tim Golden ha scritto:
> I vaguely remember that you can get an ODBC driver for CSV.

There is a standard ODBC driver for use text file or csv, in windows.
But I use Linux on production servers.
I'd like to find a Python library or tool.

Thanks!
Paolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading csv files using SQL

2007-03-01 Thread Pablo was Paolo
[EMAIL PROTECTED] ha scritto:
> If you want to work directly with the files why not just use Python's csv
> module?

Now, with Java, I use the same class to read several databases and csv 
files (with SQL instructions).
I'd like to find a library for using the same approach in Python.

Thank you,
Paolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading csv files using SQL

2007-03-01 Thread Pablo was Paolo
Paul McGuire ha scritto:
> Sqlite has an in-memory option, so that you can read in your csv, then
> load into actual tables.

Thanks, this could be the perfect solution.

Paolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading csv files using SQL

2007-02-28 Thread Pablo was Paolo
Hi,

Dennis Lee Bieber ha scritto:
>   You could maybe use SQLite to load the CSV file and process in an
> actual DBMS...

Ok, this is the solution I'm using actually (with PostGres).
My hope is to find a way to do the same thing without using a DBMS but 
working directly with the files.

Thanks a lot,
Paolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Reading csv files using SQL

2007-02-28 Thread Pablo was Paolo
Hi,
exists a Python library that allows to interface to csv files as if you 
manage a database, using SQL language?

Something like csvjdbc in Java, where table name is file name and the 
field's names are in first row.

Thanks!
Paolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Building C extensions

2006-11-06 Thread Paolo Pantaleo
Well I'm just courious: if I want to buid a C extension, I shoul use
the same compiler that has been used to build python (right?). Since
python has been built using Visual C, how can I build an extension if
I don't have Visual Studio?

PAolo
-- 
http://mail.python.org/mailman/listinfo/python-list


A py2exe like tool for Linux

2006-10-24 Thread Paolo Pantaleo
Hi,

is thre something like py2exe for Linux? I don't need to build a
standalone executable (most Linuxes have python instaled), but at
least I need to provide all the needed libraries togheter with my
source code, so users just need to download one file, and not several
libraries.

PAolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Screen capture on Linux

2006-10-23 Thread Paolo Pantaleo
Thnx everybody for the help,

actually I need somethin slightly different. I found about some
external process that can capture the screen, but since I need to
captyre the screen up to 4-5 times a second, I don't want to fork a
new process every time, so I was looking for some library...[This
method works good on Windows]

If needed, I was thinking to write a C module too. I never did it
before, but I am a not so bad C programmer... any suggestion? What
code can I read and eventually reuse? Would the xwd be useful?

Anyway doesn't it exist a Python binding for let's say X APIs ?
[I know about nothing about X programing]

2006/10/22, Theerasak Photha <[EMAIL PROTECTED]>:
> On 22 Oct 2006 09:06:53 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > Paolo Pantaleo wrote:
> > > Hi,
> > >
> > > I need to capture a screen snapshot in Linux. PIL has a module
> > > IageGrab, but in the free version it only works under Windows. Is
> > > there any package to capture the screen on Linux?
> >
> > xwd comes with the X server.  man xwd
> >
> > Most useful is "xwd -root" or similar.  You may want "sleep 5; xwd
> > -root" to give you some time to set things up as needed, or map it to a
> > window manager keybinding.
>
> The problem with that is that xwd format is a non-standard format, and
> *uncompressed* on top of that. If he wants to distribute the image to
> friends, or whatever, he'll have to convert it to something like png
> anyway. If he's using Linux, he probably doesn't need to use xwd
> anyway and might as well save himself the effort (and HD space) now.
>
> -- Theerasak
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Screen capture on Linux

2006-10-21 Thread Paolo Pantaleo
Hi,

I need to capture a screen snapshot in Linux. PIL has a module
IageGrab, but in the free version it only works under Windows. Is
there any package to capture the screen on Linux?

Thnx
PAolo
-- 
http://mail.python.org/mailman/listinfo/python-list


locals() and globals()

2006-10-14 Thread Paolo Pantaleo
Hi

this exaple:

def lcl():
n=1
x=locals()
x["n"]=100
print "n in lcl() is:" +str(n)
#This will say Name error
#x["new"]=1
#print new


n=1
x=globals()
x["n"]=100
print "gobal n is:" +str(n)
x["new"]=1
print "new is:" +str(new)
lcl()

produces

gobal n is:100
new is:1
n in lcl() is:1

shouldn't be n in lcl() 100 too?

why accessing the names dictionary globals() and locals() gives
different results?
This example was made using
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32

PAolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Tk: filling a frame with a widget

2006-10-04 Thread Paolo Pantaleo
I have this code

from Tkinter import *

root=Tk()
Button(root).pack(fill=BOTH)
root.mainloop()

I would expect the button filling all the client draw area of the
Frame, but when I resize the root window the button becomes wider, but
not higher ( I get some empty space under the button). How could set
the button to fill always all the space available?

Well maybe some other solution exists, since my problem is this:

I have a resizable window and i want to keep it filled with a Canvas
displaying an image (PhotoImage). Can I get the in some way the size
of the clien draw area of the window containig the canvas?

Thnx
PAolo

-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: postgresql database

2006-10-03 Thread Paolo

Michele Simionato ha scritto:

> Paolo wrote:
> > Ciao a tutti, sto cercando di implementare un applicazione che si
> > interfaccia con postgresql(8.1), utilizzando Psycopg2, in ambiente
> > windows (python versione 2.5). Ho installato Psycopg2 e provando
> > solamente fare: import psycopg mi ritorna il seguente errore:
> >
> > import psycopg
> > ImportError: No module named psycopg
> >
> > come mai? va settata qualche path oltre a quella di postgresql ?
> >
> > grazie dell'aiuto
>
> Well, if you are using Psycopg2, do
>
> import psycopg2

sure, I have mistaken to write the import, the problem was in the
version of the driver. Thank you for tour fast answer.

>
> (and please use the italian mailing list for questions in Italian).

sorry, but I thought to write in the italian mailing list.

> 
>  Michele Simionato

-- 
http://mail.python.org/mailman/listinfo/python-list


postgresql database

2006-10-02 Thread Paolo
Ciao a tutti, sto cercando di implementare un applicazione che si
interfaccia con postgresql(8.1), utilizzando Psycopg2, in ambiente
windows (python versione 2.5). Ho installato Psycopg2 e provando
solamente fare: import psycopg mi ritorna il seguente errore:

import psycopg
ImportError: No module named psycopg

come mai? va settata qualche path oltre a quella di postgresql ?

grazie dell'aiuto

-- 
http://mail.python.org/mailman/listinfo/python-list


VIdeo Converence Software: Tk and thread synchronization

2006-10-02 Thread Paolo Pantaleo
Hi,

I am going on writing my video conference software. I wrote the video
grab, code/decode, and netwoark (multicast) transport.

I have one thread doing this:

[thread 1]
while True:
  for some times:
my_socket.recv() #blocking here
store data
  compute image #here we have a complete new image to display

Now, I was thinking to display the image in a  Tk window. But I think
i will need a separate thread to run the mainloop() [thread 2], right?
 How can I signale to the Tk thread that a new image is ready to be
shown? I was thinkin on using an event generated for the first
(network) thread. But I don't know how to do it exactly. Any
suggestion, please?

What if I access to Tk object form thread 1, is Tk thread safe?

Thnx
PAolo

-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing Video conference software for Windows

2006-09-22 Thread Paolo Pantaleo
2006/9/22, Paolo Pantaleo <[EMAIL PROTECTED]>:
> Thnx everybody for the precious help :)
>
> Someone said about VNC... I'll take a look, but since it is an
> exercise I need to do it, I can't just say someone else arelady did
> that :)
>
> Everything seems quite useful. I forgot two specifications:
>
> 1. Screen should be split in small squares and only the changing
> squares must be transmitted (Ok it shouldn't be too difficult)
>
> 2. The comunication must be in multicast

Twisted supports multicast ( example
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/425975)

>
> I will spend some time testing the resources.
>
> PAolo
>


-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing Video conference software for Windows

2006-09-22 Thread Paolo Pantaleo
Thnx everybody for the precious help :)

Someone said about VNC... I'll take a look, but since it is an
exercise I need to do it, I can't just say someone else arelady did
that :)

Everything seems quite useful. I forgot two specifications:

1. Screen should be split in small squares and only the changing
squares must be transmitted (Ok it shouldn't be too difficult)

2. The comunication must be in multicast

I will spend some time testing the resources.

PAolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing Video conference software for Windows

2006-09-21 Thread Paolo Pantaleo
19 Sep 2006 09:42:51 -0700, Jordan <[EMAIL PROTECTED]>:
> If you're going to need win32 system access use the win32all python
> extension (very, very good extension).  Do you need single frame image
> capture, or constant video stream? PIL can be used for the first, it
> might also be usable for video, I'm not sure.
Well I need something like 5-10 fps. An issue is the comression
method: MPEG and friends aren't good (I think) for compressing stuff
with sharp borders. Maybe I could use A sequence of PNG images, but it
isn't a great solution.

For sound, python comes
> with some built in libraries, but you should also take a look at
> pysonic http://www.cs.unc.edu/Research/assist/developer.shtml.  For the
> bandwidth efficiency issue, what type of connection are you using? The
> socket module is quite capable of transmiting whatever data you have,
> so unless you're thinking of implementing some mini bittorrent like
> network in an attempt to save bandwidth I don't know what you can do
> about that. There's an extension called IPqueue which might give you
> somewhere to start for packet/bandwidth manipulation.  Check out The
> Vaults of Parnassus, which has a lot of stuff (including ogg/mp3
> converters last time a check).Big question, is this supposed to act
> like a remote desktop, or just show what's happening?  Start by
> searching Google, it's very useful.
Well the bandwidth issue is most of all related to  video compression
(see above). Well maybe 256 kbps would be nice.

It should just show what's happening.


PAolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Writing Video conference software for Windows

2006-09-19 Thread Paolo Pantaleo
Hi,

I need to write a software that allow to see the desktop and hear the
microphone capture of a remote PC across a network. I need to do that
for a unviresity assignement. The software must  run on Windows. Since
I like Python very much I am thinking to write that software in
Python. Do you thinkit is a good choice? Are there libraries for audio
compression (OGG or MP3 or maybe GSM or something like realaudio) and
video compression (btw what can be some good libraries to transmit
images of a desktop in a bandwidth-efficent way?). What about capture
of audio and screen? (Probably i will need some Win32 system call,
there are bindings in Python, aren't they?)

If I needed to write some Python modules in C, would it be difficult?

Can some language like C# or C++ may be better?

Thnx
PAolo

-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python daemon process

2006-08-27 Thread Paolo Pantaleo
2006/8/26, Thomas Dybdahl Ahle <[EMAIL PROTECTED]>:
> Hi, I'm writing a program, using popen4(gnuchess),
> The problem is, that gnuchess keeps running after program exit.
>
> I know about the atexit module, but in java, you could make a process a
> daemon process, and it would only run as long as the real processes ran. I
> think this is a better way to stop gnuchess, as you are 100% sure, that
> it'll stop.
>
> Can you do this with popen?
>
> --
> Thomas
> --
> http://mail.python.org/mailman/listinfo/python-list
>
You could send the quit (or close or wahtever) command to gnuchess
when you want it to terminate. Supposing that gnuchess needs to do
some stuff on exit, this is a better solution.

PAolo

-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: avoiding file corruption

2006-08-27 Thread Paolo Pantaleo
27 Aug 2006 00:44:33 -0700, Amir  Michail <[EMAIL PROTECTED]>:
> Hi,
>
> Trying to open a file for writing that is already open for writing
> should result in an exception.
>
> It's all too easy to accidentally open a shelve for writing twice and
> this can lead to hard to track down database corruption errors.
>
> Amir
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Even if it could be strange, the OS usually allow you to open a file
twice, that's up to the programmer to ensure the consistency of the
operations.

PAolo



-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Python & chess

2006-08-24 Thread Paolo Pantaleo
Well Python is not a good language for writing a chess engine (even if
a chess engine exists:
http://www.kolumbus.fi/jyrki.alakuijala/pychess.html), but it could be
grat for chess interfaces, for drawing boards, and similar things. I
foudn out a library for these things
(http://www.alcyone.com/software/chess/). Does anyone konw about more
chess related modules?

Thnx
PAolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: p-gal: photo gallery generator with templating support

2006-08-14 Thread Paolo Pantaleo
14 Aug 2006 10:16:37 -0700, ajaksu <[EMAIL PROTECTED]>:
> Paolo Pantaleo wrote:
> > www.sf.net/projects/ppgal
>
> Ciao Paolo!
>
> The homepage (http://paolopan.freehostia.com/p-gal/ ) looks weird in my
> SeaMonkey 1.0.4,  contents appear below GoogleAds instead of at the
> right.

Well... I designed the site for Firefox... anyway I used CSS float
directives and no tables. I don't know if I made something wrong, or
if it is a [not so unlikely] standard compliance problem. Well Firefox
too has some problems with floats.

I copied the layout from http://www.topolinux.org/ - can you see this properly?



-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Announce] p-gal: photo gallery generator with templating support

2006-08-14 Thread Paolo Pantaleo
14 Aug 2006 08:31:06 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid>:
> "Paolo Pantaleo" <[EMAIL PROTECTED]> writes:
> > I would anyone to take a look at my piece of code, and give me his
> > feedback about what is good and what should be improved.
>
> url?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Sorry...

www.sf.net/projects/ppgal
-- 
http://mail.python.org/mailman/listinfo/python-list


[Announce] p-gal: photo gallery generator with templating support

2006-08-14 Thread Paolo Pantaleo
Hi,
I'm writing a software in python to generate html photo gallery. It is
called p-gal and is GPL licensed. It is written in python [With the
invaluable help of this list :)] and it has a templating system based
on Cheetah. Currently it works under Linux (and maybe other UNIX-like
OSs)

The main idea of p-gal is to provide a framework to allow image
gallery generation, but letting the user as free as possible about the
style of the gallery. P-gal features for now only one template (or
theme), but adding new ones is very simple.

I would anyone to take a look at my piece of code, and give me his
feedback about what is good and what should be improved.

Thnx
PAolo Pantaleo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Grammar parsing

2006-08-03 Thread Paolo Pantaleo
2006/8/3, Ben Finney <[EMAIL PROTECTED]>:
> "Paolo Pantaleo" <[EMAIL PROTECTED]> writes:
>
> > How can I write a pareser for a certain gramamr? I found PyPy that
> > does it, is thare any other tool? Maybe something built-in the
> > python interpreter?
>
> The standard library gets you partway there, with 'shlex':
>
> http://docs.python.org/lib/module-shlex.html>
>
> The cheeseshop knows of 'pyparsing':
>
> http://cheeseshop.python.org/pypi/pyparsing/>
>


Thnx everybody for the help,

I finished using pyparsing actually, that is very handy and nice to use.

PAolo


-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Grammar parsing

2006-08-03 Thread Paolo Pantaleo
Hi,

How can I write a pareser for a certain gramamr? I found PyPy that
does it, is thare any other tool? Maybe something built-in the python
interpreter?

Thnx
PAolo



-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Behavior on non definded name in Cheetah

2006-08-02 Thread Paolo Pantaleo
2006/8/2, Peter Otten <[EMAIL PROTECTED]>:
> Paolo Pantaleo wrote:
>
> > 2006/8/2, Stephan Diehl <[EMAIL PROTECTED]>:
> >> Paolo Pantaleo wrote:
> >> > [I hope I am posting to the right place]
> >> >
> >> > I have a cheetah template something like this:
> >> >
> >> > x is: $x
> >> > y is: $y
> >> > z is: $z
> >> >
> >> > [Actually more complicated]
> >> >
> >> > If for example $y is not defined I get an exception and  the parsing
> >> > of the template stops. Is  there any way to substitute $y with an emty
> >> > string and making cheeta going on with parsing?
> >> >
> >> > Thnx
> >> > PAolo
> >> >
> >>
> >>
> http://cheetahtemplate.org/docs/users_guide_html_multipage/language.namemapper.missing.html
> >> --
> >> http://mail.python.org/mailman/listinfo/python-list
> >>
> >
> > Actually I wanted to keep things simple for who writes the template,
> > so I am using this workaround: I define a class
> >
> > class ClassMapper:
> > def __init__(self,dict={}):
> > self.__dict=dict
> > def getValue(self,str):
> > try:
> > return self.__dict[str]
> > except KeyError:
> > return ""
> >
> > x=ClassMapper(dict)
> > Template(definition, searchList=[{"info":x.getValue}])
> >
> >
> >
> > so the user should do
> >
> > $info("name")
> >
> > Maybe I could define a class that implements a dictionary and doesn''t
> > raise an exception for a key not present... but it seems to
> > complicated.
>
> You mean something like
>
> from Cheetah.Template import Template
>
> class Dict(dict):
> def __getitem__(self, key):
> return self.get(key, "")
>
> template = """\
> x is $x
> y is $y
> z is $z
> """
> print Template(template, searchList=[Dict(x="x", y="y")])
>
> You can also make a debugging version:
>
> class Dict(dict):
> def __getitem__(self, key):
> return self.get(key, "#missing key: %r#" % key)
>
> Peter
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Wonderful, thnx a lot. Well not so complicated if you know how to do :D

PAolo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Behavior on non definded name in Cheetah

2006-08-02 Thread Paolo Pantaleo
2006/8/2, Stephan Diehl <[EMAIL PROTECTED]>:
> Paolo Pantaleo wrote:
> > [I hope I am posting to the right place]
> >
> > I have a cheetah template something like this:
> >
> > x is: $x
> > y is: $y
> > z is: $z
> >
> > [Actually more complicated]
> >
> > If for example $y is not defined I get an exception and  the parsing
> > of the template stops. Is  there any way to substitute $y with an emty
> > string and making cheeta going on with parsing?
> >
> > Thnx
> > PAolo
> >
>
> http://cheetahtemplate.org/docs/users_guide_html_multipage/language.namemapper.missing.html
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Actually I wanted to keep things simple for who writes the template,
so I am using this workaround: I define a class

class ClassMapper:
def __init__(self,dict={}):
self.__dict=dict
def getValue(self,str):
try:
return self.__dict[str]
except KeyError:
return ""

x=ClassMapper(dict)
Template(definition, searchList=[{"info":x.getValue}])



so the user should do

$info("name")

Maybe I could define a class that implements a dictionary and doesn''t
raise an exception for a key not present... but it seems to
complicated.

PAolo

-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Behavior on non definded name in Cheetah

2006-08-02 Thread Paolo Pantaleo
[I hope I am posting to the right place]

I have a cheetah template something like this:

x is: $x
y is: $y
z is: $z

[Actually more complicated]

If for example $y is not defined I get an exception and  the parsing
of the template stops. Is  there any way to substitute $y with an emty
string and making cheeta going on with parsing?

Thnx
PAolo

-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python - regex handling

2006-07-04 Thread Paolo Pantaleo
2006/7/4, bruce <[EMAIL PROTECTED]>:
> hi...
>
> does python provide regex handling similar to perl. can't find anything in
> the docs i've seen to indicate it does...
>
> -bruce
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
http://python.org/doc/2.4.1/lib/module-re.html

Here is the documentation about re, I think that if you spend an hour
or two reading it, you will know about everything you need.

Paolo

-- 
If you like Python as I do, you can find useful my little Python resource center
http://ppp3.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Specifing arguments type for a function

2006-06-20 Thread Paolo Pantaleo
I have a function

def f(the_arg):
...

and I want to state that the_arg must be only of a certain type
(actually a list). Is there a way to do that?

Thnx
PAolo

-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting backtrace on an axception

2006-06-10 Thread Paolo Pantaleo
So I have this code

try:
do something
except:
 do something else

In the except block I need to print detailed output about the error
occured, and in particular I need to read the backtrace for the line
that raised the exception [then modify and print it]. I know about the
exception.extract_tb() and friends, but I can't figure out how they
works.

Can somebody exlpain me?

Thnx
PAolo


-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Request for comment: programmer starting page (micro knowledge base)

2006-05-24 Thread Paolo Pantaleo
I am writting down a pege with useful links for a Python programmer.
That is reference, tutorials and anything that can be useful. I use it
regulary when programming in Python and I can't do without it.

I would be happy if you go and see that page, and tell me what you
think about and suggest links to be added.

The page is : http://ppp3.co.nr

Thnx
Paolo Pantaleo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Includeing Python in text files

2006-05-23 Thread Paolo Pantaleo
2006/5/23, Chris Smith <[EMAIL PROTECTED]>:
> Diez B. Roggisch wrote:
> > Paolo Pantaleo wrote:
> >
> >
> >>I am working on this:
> >>
> >>I have  a text file, containig certain section in the form
> >> >>  python code here
> >>py?>
> >>
> >>I parse the text file and substitute the python code with its result
> >>[redirecting sys.stdin to a StringIO]. It something like php or
> >>embedded perl.
> >>
> >>So my little toy works not bad, but I was wondering if such a feature
> >>already existed, if yes, can you point me out some links?
> >
> >
> > Its a templating system, and there are a gazillion out there. Some of them
> > are listed here:
> >
> > http://www.cherrypy.org/wiki/ChoosingATemplatingLanguage
> >
> >
> > Diez
> >
> >
> >
> I'm just getting into programming so this may be a dumb question...but
> why would you want to do this? What is templating good for?
>
> Chris
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Well php is base on this principle, most (server side) dynamic sites
are based on some template sistem

PAolo

-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Includeing Python in text files

2006-05-22 Thread Paolo Pantaleo
I am working on this:

I have  a text file, containig certain section in the form


I parse the text file and substitute the python code with its result
[redirecting sys.stdin to a StringIO]. It something like php or
embedded perl.

So my little toy works not bad, but I was wondering if such a feature
already existed, if yes, can you point me out some links?

Thnx
PAolo

-- 
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: test assignmet problem

2006-04-24 Thread Paolo Pantaleo
2006/4/23, Paul McGuire <[EMAIL PROTECTED]>:
>
> "Paolo Pantaleo" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> So I tried this
>
> if(not (attr=global_re.match(line)) ):
> break
>
> it says  invalid syntax [on the =]
>   ... because this syntax is not valid ...
>
> so it is not possible to do test and assignment in C style?
>   ... no it's not, see
> http://www.python.org/doc/faq/general/#why-can-t-i-use-an-assignment-in-an-expression
>
> how can I write this otherwise?
>   ... is this so bad?...
>
> attr=global_re.match(line)
> if not attr:
> break
>
>   ... or, since you don't seem to be doing much with attr, you could just do
>
> if not global_re.match(line):
> break
>
>   ... and get rid of all those distracting ()'s!
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Thnx for the help,
actually the problme is not solved

i have [well I want to do...] something like:

if a=b():
   do stuff with a
else if a=c():
   do stuff with b
else:
   do other stuff

well, two solutions are

a1=b()
a2=c()

if a1:
   do stuff with a1
else if a2:
   do stuff with a2
else:
   do other stuff


the other is


if b():
   a=b()
   do stuff with a
else if c():
   a=c()
   do stuff with b
else:
   do other stuff

Even if none is exactly the same about:
 * the number of times the b() and c() functions are executed
 * the final value of a

I think the right one is:

a=b()
if a:
   do stuff with a
else:
   a=c()
   if a=c():
   do stuff with b
   else:
do other stuff


PAolo
--
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


test assignmet problem

2006-04-23 Thread Paolo Pantaleo
So I tried this

if(not (attr=global_re.match(line)) ):
break

it says  invalid syntax [on the =]
so it is not possible to do test and assignment in C style?
how can I write this otherwise?

Thnx
PAolo
--
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list example

2006-04-23 Thread Paolo Pantaleo
2006/4/22, Edward Elliott <[EMAIL PROTECTED]>:
> No substantive problems.  The str() calls are unnecessary, print calls
> list.__str__ already.  You can replace the loop with list comprehensions or
> slices.  Same result, a bit more succinct.  See these pages for more:
>
> http://docs.python.org/lib/typesseq.html
> http://docs.python.org/tut/node7.html  (section 5.1.4)
>
>

Thnx, I didn't catch the use of colon in print...

Thanks to the other posting, but actually I want to write some code
that one can modify to his own needings

PAolo
-- 
http://mail.python.org/mailman/listinfo/python-list


list example

2006-04-22 Thread PAolo
Hi,
I wrote this small example to illustrate the usage of lists:

even=[]
odd=[]

for i in range(1,10):
if i%2:
odd.append(i)
else:
even.append(i)

print "odd: "+str(odd)
print "even: "+str(even)

numbers=even
numbers.extend(odd)
print "numbers:"+str(numbers)
numbers.sort()
print "sorted numbers:"+str(numbers)


any comment, suggestion? Is there something not elegant?

Thnx
PAolo

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python university search

2005-12-05 Thread Paolo Alexis Falcone
On Sun, 04 Dec 2005 17:12:45 -0800, josh wrote:

> [pardon me if this is not the appropriate list]
> 
> hello,
> 
> i am interested in doing an undergraduate major in computer science
> that mainly focuses on python as a programming language..
> 
> i am not a very bright student and neither do i have the money to
> think about universities like caltech, stanford etc. i am looking for
> a university that is easy to get admitted in and yet i can get good
> knowledge and education out of it.
> 
> also english is not my first language and i feel that acts against me,
> but i do have a strong desire to learn.
> 
> i have read the tutorials in python.org and understand the python
> programming syntax but i feel that only a computer science class is
> going to teach me how to program and apply advance concepts.  if any
> of you happen to know good video tutorials or self study materials or
> tips  that can act as an alternative to going to college, would you
> please mind sharing or selling for something reasonable.

Try looking for these online references:
* http://www.aduni.org - website of the defunct ArsDigita University. They
have a plethora of resources that can be downloaded, or obtained in a
couple of DVD's
* http://www.ibiblio.org/obp/thinkCSpy - How to think like a Computer
Scientist: Learning with Python (checkout their bibliography too.
* http://mitpress.mit.edu/sicp/ - Structure and Interpretation of Computer
Programs. Not Python, but should give you a good material for functional
programming - which is another paradigm that Python also supports.

Try reading these (buy/steal :D) from your library:
* The Art of Computer Programming (D. Knuth). 3 volumes and a fascicle of
an upcoming volume. Very terse reading, but should you overcome this,
you're on the way to computing greatness

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Standalone applications ?

2005-08-13 Thread Paolo Alexis Falcone
On Sat, 13 Aug 2005 23:29:27 -0400, Madhusudan Singh wrote:

> Hi
> 
> I just finished developing an application using Qt Designer in Python that
> uses pyqwt, gpib, etc. How does one create standalone executables for
> applications such as these ?

Generally, you can't, as Python is an interpreted programming language.
However, there are some projects like py2exe in Windows which approximates
what you want to do - port the Python code into a stand-alone application.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: set of sets

2005-08-11 Thread Paolo Veronelli
Paolino wrote:
> I thought rewriting __hash__ should be enough to avoid mutables problem but:
> 
> class H(set):
>def __hash__(self)
>  return id(self)
> 
> s=H()
> 
> f=set()
> 
> f.add(s)
> f.remove(s)
> 
> the add succeeds
> the remove fails eventually not calling hash(s).
> 

Yes this is really strange.

from sets import Set
class H(Set):
   def __hash__(self):
 return id(self)

s=H()
f=set() #or f=Set()

f.add(s)
f.remove(s)

No errors.

So we had a working implementation of sets in the library an put a 
broken one in the __builtins__ :(

Should I consider it a bug ?

Regards Paolino


___ 
Aggiungi la toolbar di Yahoo! Search sul tuo Browser, e'gratis! 
http://it.toolbar.yahoo.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: set of sets

2005-08-11 Thread Paolo Veronelli
Matteo Dell'Amico wrote:
> Paolino wrote:
> 
>>I thought rewriting __hash__ should be enough to avoid mutables problem 
>>but:
>>
>>class H(set):
>>  def __hash__(self)
>>return id(self)
>>
>>s=H()
>>
>>f=set()
>>
>>f.add(s)
>>f.remove(s)
>>
>>the add succeeds
>>the remove fails eventually not calling hash(s).
> 
> 
> Why don't you just use "frozenset"?
> 
And mostly with sets remove operation expense should be sublinear or am
I wrong?
Is this fast as with lists?
Obviously if I use the ids as hash value nothing is guaranted about the
objects contents to be unique but I don't care.
My work is a self organizing net,in which the nodes keep a structure to
link other nodes.As the nature of the net,the links are moved frequently
  so remove and add operations and contains query should be optimized.
Why objects need to be hashable for this? Isn't __hash__ there to solve
the problem?
PS Looks like the problem is not present in class sets.Set






___ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to turn a variable name into a string?

2005-03-11 Thread Paolo G. Cantore
Hi Stewart,
what about the other way, string -> var and not var -> string?
My suggestion:
mylist = ["a", "b", "c"]
for my in mylist:
   if locals()[my] == None:
  print "you have a problem with %s" % my
Paolo
Stewart Midwinter wrote:
I'd like to do something like the following:
a = 1; b = 2; c = None
mylist = [a, b, c]
for my in mylist:
if my is None:
print 'you have a problem with %s' % my #this line is problematic

You have a problem with None

What I want to see in the output is:
You have a problem with c

How do I convert a variable name into a string?
thanks!
--
http://mail.python.org/mailman/listinfo/python-list


deriving from str

2004-12-23 Thread Paolo Veronelli
I want to add some methods to str class ,but when I change the __init__ 
methods I break into problems

class Uri(str):
def __init__(self,*inputs):
print inputs
if len(inputs)>1:
str.__init__(self,'<%s:%s>'%inputs[:2])
else:
str.__init__(self,inputs[0])
print inputs
a=Uri('ciao','gracco')
Traceback (most recent call last):
  File "prova.py", line 9, in ?
a=Uri('ciao','gracco')
TypeError: str() takes at most 1 argument (2 given)
where is the  str() wrong call.I suppose It's the __new__ method which 
is wrong or me .Thanks for help

--
http://mail.python.org/mailman/listinfo/python-list