Re: List open files

2008-04-08 Thread Guillaume
Oh and don't forget to take care about saving correctly the Oracle 
database ! ^^
(private joke *giggles* j/k :))

Regards,
-- 
Guillaume
-- 
http://mail.python.org/mailman/listinfo/python-list


How to set the socket type and the protocol of a socket using create_connection?

2012-08-20 Thread Guillaume Comte
Hello everyone,

I want to use socket.create_connection(...) to set a source address in a ping 
implementation in python.

But how can I then set the type and the protocol? Because, before, I did:

icmp = socket.getprotobyname("icmp")
my_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)

But now, I do:

src_addr = socket.gethostbyname(src_addr)
dest_addr = socket.gethostbyname(dest_addr)
my_socket = socket.create_connection(dest_addr, socket.getdefaulttimeout(), 
src_addr)

Is there something like my_socket.setproto()? I haven't found such a function 
in the documentation.

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


Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-20 Thread Guillaume Comte
In fact, socket.create_connection is for TCP only so I cannot use it for a ping 
implementation. Does anyone have an idea about how to be able to set a source 
address for ICMP messages?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-20 Thread Guillaume Comte
Le lundi 20 août 2012 15:38:14 UTC+2, Hans Mulder a écrit :
> On 20/08/12 14:36:58, Guillaume Comte wrote:
> 
> > In fact, socket.create_connection is for TCP only so I cannot use it for a 
> > ping implementation.
> 
> 
> 
> Why are you trying to reimplement ping?

Because I work on a network emulator and I want to check biterros patterns so I 
need to access the data of the packets. An dsince my test program is written in 
Python, it's easier to do it in Python.

> 
> 
> 
> All OS'es I am aware of come with a working ping implementation.
> 
> 
> 
> 
> 
> > Does anyone have an idea about how to be able to set a source address for 
> > ICMP messages?
> 
> 
> 
> Did you try not setting it?
> 
> 
> 
> The default is probably your own IP address, which is the only
> 
> sensible value anyway.  Or are you trying to cause confusion
> 
> by sending ICMP packets with a forged source address?

No, I want to do it on a machine with aliases as in:

ifconfig em0 10.0.1.1 netmask 255.255.255.0 alias
ifconfig em0 10.0.2.1 netmask 255.255.255.0 alias
ping -c4 -S 10.0.1.1 10.0.2.1


But I think I've found the solution: my_socket.bind((src_addr, 1))

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


Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-21 Thread Guillaume Comte
Unfortunatly, my_socket.bind((src_addr, 1)) doesn't work. I get the error 
message: "socket.error: [Errno 49] Can't assign requested address"...

I've tried to change the protocol to IPPROTO_RAW. Here is a simple example of 
the code:



import socket
import os
import struct
import time
import select

ICMP_ECHO_REQUEST = 8
PACKET_SIZE = 64 # Bytes
TIMEOUT = 0.5 # Seconds

def do_one(src_addr, dest_addr):
my_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, 
socket.IPPROTO_RAW)

if src_addr != None:
src_addr = socket.gethostbyname(src_addr)
my_socket.bind((src_addr, 1))

my_id = os.getpid() & 0x

print "id: " + str(my_id)

print "sending..."
send_one(dest_addr, my_socket, my_id)

print "receiving..."
id = receive_one(my_socket)
if id == None:
print "nothing received !"
else:
print "received id: " + str(id)

my_socket.close()

def checksum(source_string):
...

def send_one(addr, my_socket, id):
# Header: type (8), code (8), checksum (16), id (16), sequence number (16)
cs = 0
header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, cs, socket.htons(id), 0)
data = PACKET_SIZE * "G"

cs = checksum(header + data)

header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, socket.htons(cs), 
socket.htons(id), 0)
packet = header + data

my_socket.sendto(packet, (socket.gethostbyname(addr), 1))

def receive_one(my_socket):
while True:
what_ready = select.select([my_socket], [], [], TIMEOUT)
if what_ready[0] == []:
return None

received_packet = my_socket.recvfrom(1024)[0]
header = received_packet[20:28]
id = struct.unpack("bbHHh", header)[3]
return socket.ntohs(id)

if __name__ == "__main__":

import sys
dst = sys.argv[1]
print "dst: " + dst
try:
src = sys.argv[2]
print "src: " + src
except IndexError:
src = None
do_one(src, dst)


But when I try to set a source address, I still get the same error message...

Does anyone know how I could build the IP header (I don't even know if it can 
be the solution but it's worth a try...)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-22 Thread Guillaume Comte
Le mercredi 22 août 2012 04:10:43 UTC+2, Dennis Lee Bieber a écrit :
> On Tue, 21 Aug 2012 10:00:28 -0700 (PDT), Guillaume Comte
> 
>  declaimed the following in
> 
> gmane.comp.python.general:
> 
> 
> 
>   A later follow-up
> 
> > Unfortunatly, my_socket.bind((src_addr, 1)) doesn't work. I get the error 
> > message: "socket.error: [Errno 49] Can't assign requested address"...
> 
> > 
> 
> 
> 
>   Since .bind() is used to set up a /listener/, the network stack
> 
> (LINK layer) probably has to be tied to the IP address; that is, a valid
> 
> "source" address needs to be supplied to .bind.
> 
Do you mean that an alias is not a valid source address? Because ping.c can do 
it...

I've also tried changing the port to  or 8080 but the same error happens.
> 
> 
> 
> 
> > But when I try to set a source address, I still get the same error 
> > message...
> 
> > 
> 
> > Does anyone know how I could build the IP header (I don't even know if it 
> > can be the solution but it's worth a try...)?
> 
> 
> 
>   Based upon http://linux.die.net/man/7/raw "Raw sockets allow new
> 
> IPv4 protocols to be implemented in user space. A raw socket receives or
> 
> sends the raw datagram not including link level headers. " implies that
> 
> you need to build the entire IP packet for your ICMP message... That
> 
> means you do NOT use socket methods to set fields -- you'll probably
> 
> have to use something like the struct module to lay out the entire IP
> 
> packet /including/ header contents, and then pass that as-is to the
> 
> socket.
> 
> 
> 
> -- 
> 
>   Wulfraed Dennis Lee Bieber AF6VN
> 
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/

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


Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-22 Thread Guillaume Comte
I've managed to build the IP header. I've put the source and destination 
addresses in this header but it doesn't change the real source address...

I'm trying to read the ping source code but I'm lost...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-22 Thread Guillaume Comte
Le mercredi 22 août 2012 11:03:11 UTC+2, Hans Mulder a écrit :

> 
> On my laptop, 0 appears to be the only port number that bind accepts
> 
> for a raw socket.  Other numbers I tried all raise "socket.error:
> 
> [Errno 49] Can't assign requested address".
> 
> 
> 
> But this might depend on your OS.  What OS are you using?
> 

I'm using FreeBSD 7.3
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem using s.strip() to remove leading whitespace in .csv file

2012-02-29 Thread Guillaume Chorn
Hello All,

I have a .csv file that I created by copying and pasting a list of all the
players in the NBA with their respective teams and positions (
http://sports.yahoo.com/nba/players?type=lastname&first=1&query=&go=GO!).
Unfortunately, when I do this I have no choice but to include a single
leading whitespace character for each name.  I'd like to compare this list
of names to another list (also in .csv format but in a different file)
using a simple Python script, but in order to do that I need to strip the
leading whitespace from all of the names or none of them will match the
names in the second list.  However, when I try to do this as follows:

positions = open('/home/guillaume/Documents/playerpos.csv')

for line in positions:
info = line.split(',')
name = info[0]
name = name.strip()
print name #to examine the effect of name.strip()

I keep getting all of the names with the leading whitespace character NOT
removed (for example: " Jeff Adrien". Why is this happening?

The following is a sample of the .csv file (the one I'm trying to remove
the whitespace from) opened in gedit, the built-in Ubuntu text editor:

 Jeff Adrien,SF,Houston Rockets
 Arron Afflalo,SG,Denver Nuggets
 Maurice Ager,GF,Minnesota Timberwolves
 Blake Ahearn,PG,Los Angeles Clippers
 Alexis Ajinca,FC,Toronto Raptors
 Solomon Alabi,C,Toronto Raptors
 Cole Aldrich,C,Oklahoma City Thunder
 LaMarcus Aldridge,FC,Portland Trail Blazers
 Joe Alexander,SF,New Orleans Hornets
 Lavoy Allen,FC,Philadelphia 76ers
 Malik Allen,FC,Orlando Magic
 Ray Allen,SG,Boston Celtics
 Tony Allen,GF,Memphis Grizzlies
 Lance Allred,C,Indiana Pacers
 Rafer Alston,PG,Miami Heat

Any help with this seemingly simple but maddening issue would be much
appreciated.

thanks,
Guillaume
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem using s.strip() to remove leading whitespace in .csv file

2012-02-29 Thread Guillaume Chorn
Thanks, the suggestion

print name.decode("utf-8").strip()

worked like a charm.  When I did the print repr(name) I got exactly what
you predicted.  I'm not yet sure what all of this means, but I'm going to
read this <http://docs.python.org/howto/unicode.html> in the hopes of
finding out.  Anyway thanks again for the help!


cheers,
Guillaume
-- 
http://mail.python.org/mailman/listinfo/python-list


err: A cool new chatbot written and extensible in python

2012-06-10 Thread Guillaume BINET
Hi all,

We have released a cool extensible chatbot for your development teams
chatrooms. At my current company we have a ton of fun with it so we
have decided to spread the love and release it as an open source
project.

Of course it is written and extensible in Python.

Feel free to give it a try. Any feedback is welcome !

Its homepage is http://gbin.github.com/err/

Some sample commands : http://github.com/gbin/err/wiki/Catalog

If you want to see our easy it is to write your own extensions to
integrate it with other tools of your company, have a look here :
https://github.com/gbin/err/wiki/plugin-dev

Feel free to contact us if you have cool plugins to submit !

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


Windows installation - questions about DLLs

2005-07-01 Thread Guillaume Hiron
Hi,

I need to install python (2.3.5) on windows without the giving installer
program.
Do you know what dlls are needed?
I found python23.dll, but the other (msvcrt.dll,msvcrit.dll) seems not
be useful.
Is there other dll? Are msvcrt.dll and msvcrit.dll used by
something?(test/test___all__.py return no error whitout these two dlls).

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


Re: pyserial with binary data

2004-11-30 Thread Guillaume Weymeskirch
Hi,

I've got the same problem. Errno 11 is because too much data, sending
is in progress.

Fix is easy: assign a non zero value to the writeTimeout property of
your serial objet.
Then the write method will wait up to this time for sending data.

Hope that's help

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


distutils

2005-04-04 Thread Guillaume JULLIEN
Hi,
New to python, I' m trying to use distutils.
And I get this error
# python setup.py build
Traceback (most recent call last):
  File "setup.py", line 89, in ?
from distutils import core
ImportError: No module named distutils
I have Python 2.3.4 installed
Any advice ?
How does path work in python ?
Thanks a lot for your help
Guillaume
--
http://mail.python.org/mailman/listinfo/python-list


Re: garbage collector and slowdown (guillaume weymeskirch)

2008-10-05 Thread guillaume weymeskirch
Thanks !
No more slowdown in python 2.6, both on gentoo and winxp systems.

I love python so much so I can live with that until I will upgrade to
the 2.6 version.
--
http://mail.python.org/mailman/listinfo/python-list


Shelve or pickle module

2008-05-17 Thread Guillaume Bog
Hello,

I read and re-read "Python in a Nutshell" written by Alex Martelli,
who knows what he is talking about. I'm a bit new to python and I'm
going to start doing persistence side on a project. Martelli's book
seems to tell me that I should use shelve module, but any code I
browsed is using pickle instead. Is there any reason to prefer pickle
over shelve?

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


Re: php vs python

2008-05-25 Thread Guillaume Bog
On Mon, May 26, 2008 at 8:12 AM, Jerry Stuckle <[EMAIL PROTECTED]>
wrote:

> Ivan Illarionov wrote:
>
>> On Sun, 25 May 2008 17:09:43 -0400, Jerry Stuckle wrote:
>>
>>> Not at all.  I do it every day.
>>>
>>> And BTW - yes, I write Python, also.  But I find I can write better,
>>> faster code in PHP.
>>>
>>
>> I find I can write better code in Python. Maybe it's just a matter of
>> personal preference?
>>
>>  Do you write PHP?
>>>
>> I did. And I hated it very much. I hated it so much that even I had few
>> Python scripts that generated PHP for me when it was possible.
>>
>>
> So you really don't write PHP.  Enough said.


I write or review PHP code everyday. While much can be done in PHP5 I still
feel Python has a cleaner definition and therefore allows writing faster
clean code.

I many places around I see people saying "doing XX is evil" or "YY
tool/function is now on my blacklist". Most of the time it is because of an
undocumented bug, unpredictable side-effect, or obscure security issue. This
propagates fears, and fears are not, in my opinion and experience, the best
companion of developers. It makes you stick on only the domain you know, and
write code very slowly and defensively. Fear comes from what we don't
understand. Take Regexp for example: when I came first to my current job,
nobody used them, everyone feared them, because Regexp can "bite" (i.e. do
something strange you cannot explain easily). After some time and patiently
explain Regexp sample to my teammates, everyone now want to play with them
(even when using them makes no sense).

If a language makes their users more confident and propagates less fears, I
would say it is better than the others in this respect. PHP has a good
documentation with user comments, which makes me more confident (I'll find a
solution) but, in my opinion, Python is better in this respect because the
way it has been crafted makes me more confident. (Often, when I open a PHP
application, the first 100 lines will be defensive stuff against
magic_quotes or other weird settings, while when I open Python third-party
modules, the first lines are most often nice docstrings, and the next lines
are easy to decipher classes and functions just doing the work.)

PHP did bite me hard (like a wild dog) at least once (postgreSQL NULL values
fetched through pg_fetch_object were both null and not null !... the bug was
very hard to find)

ASP / MSSQL did bite me a lot (like a dangerous snake) with undocumented
bugs, and so on.

Javascript can bite (like a wild cat) but can be domesticated through
frameworks like prototype.js

CSS can bite while HTML usually can't

As everyone knows pythons doesn't bite! (Or at least didn't bite me yet.)


>
>
> --
> ==
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> [EMAIL PROTECTED]
> ==
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list

Re: How do web templates separate content and logic?

2008-06-29 Thread Guillaume Bog
On Mon, Jun 30, 2008 at 11:27 AM, Tim Roberts <[EMAIL PROTECTED]> wrote:

> John Salerno <[EMAIL PROTECTED]> wrote:
> >
>
>
> If it seems out of place to you, then you shouldn't do it.  In general, you
> need to find a model that makes sense to you, and that allows you to write
> readable, workable, maintainable code.


Yes, and MVC is not the last word for it. I have seen enormous snake nests
of PHP code done in MVC, most of the problem coming from a strict
(mis)application of MVC model. On the opposite, I sometime write HTML code
straight inside the SQL's SELECT, which is pure heresy, and still get clean
code that works. For me MVC is like strict encapsulation, it is probably
useful when one guy touch the database, the other the HTML/CSS, and a third
glue things with a script, all of them knowing nearly nothing about the
rest. We don't work like this, so I don't know...



>
> --
> Tim Roberts, [EMAIL PROTECTED]
> Providenza & Boekelheide, Inc.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list

garbage collector and slowdown (guillaume weymeskirch)

2008-10-04 Thread guillaume weymeskirch
Hello everybody,


To test the python 2.5 garbage collector, I wrote a trivial script
allocating dummy objects of various sizes, then forgetting them in a loop.
The garbage collector seems working well, limiting the memory used.

But I've noticed a near linear slowdown of the execution : after a few
minutes - and several millions of allocated and freed objects, each
iteration take more and more time to execute.

Does anybody have noticed this ? Could python suffers from some memory
fragmentation in long running processes ?

I've got the same slowdown in python 2.5.2 on a 64 bits gentoo linux
box, and on a winxp machine.
FYI, the following script shows this : it prints the seconds taken for
each iteration.

--- cut here ---

import random,sys
from timeit import Timer

class Reference(object):
refcount = {}

def __init__(self):
name = self.__class__.__name__
c = self.refcount.setdefault(name,0)
self.refcount[name] = c + 1


class ClassicSmall(Reference):
def __init__(self):
super(ClassicSmall,self).__init__()
self.a = 0;
self.b = 2;
self.c = random.randint(0,500)
self.d = random.randint(0,500)


class ClassicBig(Reference):
def __init__(self):
super(ClassicBig,self).__init__()
self.mylist = range(1000)


class Tree(Reference):
def __init__(self,left,right):
super(Tree,self).__init__()
self.left = left
self.right = right
self.data = ''.join([chr(x) for x in range(65,128)])


def doit():
smalls = []
bigs = []
trees = []
for i in xrange(3):
smalls.append(ClassicSmall())
bigs.append(ClassicBig())
trees.append(Tree(1,2))


if __name__ == '__main__':
t = Timer("doit()", "from __main__ import doit; gc.enable()")
min = 0.9e300; max=0.
try:
while True:
d = t.timeit(1)
if d < min:
min = d
if d > max:
max = d
print d
except:
pass
print Reference.refcount
print "max=%f min=%f " % (max,min)

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


[Ask for Review] Scalpl: A lightweight wrapper to operate on nested dictionaries (yet another)

2017-05-29 Thread guillaume . paulet

Hi everyone :)

I wanted to share with you the work I have done for the past few days. 
It is the first time for me to make my code public, so I would really 
appreciate if some of you find time to give me feedbacks and tips 
regarding this project :)


So, here is Scalpl !
https://github.com/ducdetronquito/scalpl

It is a lightweight wrapper that helps you to operate on nested 
dictionaries through the built-in dict API, by using dot-separated 
string keys.


You might find it useful when working with document-oriented database 
queries, REST APIs, configuration files, etc...


It's *not* a drop-in replacement for your dictionaries, just syntactic 
sugar to avoid this['annoying']['kind']['of']['things'] and 
prefer['a.different.approach'].


The benefits of Scalpl are the following:

- Faster than addict or Box.
- Allows you to use the entire dict API 'with.this.kind.of.keys'.
- Almost no instantiation/conversion cost, it's just a wrapper.

You can install it via pip (Python3 only):


pip3 install scalpl


Have a great week :) !

Guillaume

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


Re: Circular iteration on tuple starting from a specific index

2017-05-30 Thread guillaume . paulet

Hi Beppe !

There are some powerful tools in the standard *itertools* module, you 
should have a look at it :)

https://docs.python.org/3/library/itertools.html

This is what I would do to cycle over you iterable without making 
several copies of it.


```
from itertools import islice, chain

def cycle_once(iterable, start):
return chain(islice(iterable, start, None), islice(iterable, start))

my_iterable = ('A','B','C','D','E','F','G','H')

for e in cycle_once(my_iterable, 2):
print(i)
```

Ps: I am pretty new to how a mailing list works. If I answered the wrong 
way, do not hesitate to tell me :)

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


Re: Circular iteration on tuple starting from a specific index

2017-06-02 Thread guillaume . paulet
@Gregory Ewing: you were right, your version without *chain* is faster 
and I quiet like it :)


```
from timeit import timeit
from itertools import chain, cycle, islice

def cycle_once_with_chain(sequence, start):
 return chain(islice(sequence, start, None), islice(sequence, 
start))



def cycle_once_without_chain(sequence, start):
 return islice(cycle(sequence), start, start + len(sequence))


sequence = tuple(i for i in range(100))

time_with_chain = timeit(
stmt='cycle_once_with_chain(sequence, 50)',
number=100, globals=globals()
)
print('Method with *chain* took: ', (time_with_chain /100), ' per 
call.')

# Method with *chain* took:  5.02595758977e-07  per call.

time_without_chain = timeit(
stmt='cycle_once_without_chain(sequence, 50)',
number=100, globals=globals()
)
print('Method without *chain* took: ', (time_without_chain /100), ' 
per call.')

#Method without *chain* took:  3.5880194699984714e-07  per call.
```

@Ian: Good point here, these two methods only works with sequences 
(list, tuple, string...).


I renamed it appropriately in the above sample code :)
--
https://mail.python.org/mailman/listinfo/python-list


New release of Scalpl (v0.2.4) ✨🍰✨

2017-06-08 Thread guillaume . paulet

Good morning evernyone !

I released a new version (0.2.4) of Scalpl yesterday evening which is 
available on PyPI :)

https://github.com/ducdetronquito/scalpl
https://pypi.python.org/pypi/scalpl/

Scalpl is a lightweight wrapper that helps you to operate on nested 
dictionaries through the built-in dict API, by using dot-separated 
string keys.
It's not a drop-in replacement for your dictionnaries, just syntactic 
sugar to avoid this['annoying']['kind']['of']['things'] and 
prefer['a.different.approach'].
It aims to keep the power of the standard dict API while being lighter 
and faster that Box or Addict.


This new release allows you to traverse nested list in your 
dictionnaries:


```
from scalpl import Cut
data = {...}
proxy = Cut(Data)
proxy.update({'users[42][0].skills', 'Python'})
# data['users'][42][0]['skills'] == 'Python
```

It also contains:
* A pretty good refactoring of the code base.
* Better exceptions
* More tests

I also tried to improve the README, with a benchmark section and a FAQ.

I would really appreciate your feedbacks to improve this project !

Have a great day :)

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


Release of Scalpl (v0.2.5) ✨🍰✨ - a lightweight wrapper for your nested dictionaries

2017-06-26 Thread guillaume . paulet

Hi everyone !

I released a new version (0.2.5) of **Scalpl** which is available on 
PyPI :)


https://github.com/ducdetronquito/scalpl

You can install it via pip:
pip3 install scalpl

Scalpl is a lightweight wrapper that helps you to operate on nested 
dictionaries through the built-in dict API, by using dot-separated 
string keys.


You might find it useful when working with document-oriented database 
queries, REST APIs, configuration files, etc...


It's not a drop-in replacement for your dictionaries, just syntactic 
sugar to avoid this['annoying']['kind']['of']['things'] and 
prefer['a.different.approach'].


The benefits of Scalpl are the following:

* Faster than addict or Box.
* Allows you to use the entire dict API 'with.this.kind.of.keys'.
* Almost no instantiation/conversion cost, it's just a wrapper.


This new release (0.2.5) is just a small API improvement.

In the previous version of Scalpl, if you wanted to iterate a list of 
dictionaries and and operate on it, you would have done the following:


```
data = {
'pokemons': [
{
'name': 'Bulbasaur',
'type': ['Grass', 'Poison'],
'category': 'Seed',
'ability': 'Overgrow'
},
{
'name': 'Charmander',
'type': 'Fire',
'category': 'Lizard',
'ability': 'Blaze',
},
{
'name': 'Squirtle',
'type': 'Water',
'category': 'Tiny Turtle',
'ability': 'Torrent',
}
],
'trainers': [
{
'name': 'Ash',
'hometown': 'Pallet Town'
}
]
}
proxy = Cut(data)
pokemons = proxy['pokemons']
for pokemon in Cut.all(pokemons):
pokemon.setdefault('moves.Scratch', {'power': 40})
```

Now, the API allows you to provied composite key directly to the Cut.all 
method:


```
for pokemon in proxy.all('pokemons'):
pokemon.setdefault('moves.Scratch', {'power': 40})
```

Do not hesitate to give me feedbacks on the module itself, it is one of 
my first public project !


Have a great afternoon :)
--
https://mail.python.org/mailman/listinfo/python-list


import from environment path

2011-06-17 Thread Guillaume Martel-Genest
Hi,

Here's my situation : I got a script a.py that need to call b.py. The
2 scripts can't be in a same package. Script a.py knows the path of
b.py relative to an environment variable B_PATH, let's say B_PATH/foo/
b.py. The solution I found is to do the flowwing :

b_dir = os.path.join(os.environ['B_PATH'], 'foo')
sys.path.append(b_dir)
import b
b.main()

Is it the right way to do it, should I use subprocess.call instead?
-- 
http://mail.python.org/mailman/listinfo/python-list


Handling import errors

2011-06-21 Thread Guillaume Martel-Genest
What is the pythonic way to handle imports error? What is bugging me
is that the imports can't be inside a function (because I use them in
different places in the script and thus they have to be in the global
scope). I would write something like:

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


Handling import errors

2011-06-21 Thread Guillaume Martel-Genest
What is the pythonic way to handle imports error? What is bugging me
is that the imports can't be inside a function (because I use them in
different places in the script and thus they have to be in the global
scope). I would write something like:

try:
import foo
except ImportError:
logging.error('could not import foo')
sys.exit(1)

But logging is not configured at this point as my main() have not been
called yet.

Should I define a global variable and assign it to my module later? Or
should I let the exception happen and let the stack trace be the error
message?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Handling import errors

2011-06-22 Thread Guillaume Martel-Genest
I did not think about using a global variable, and the top-level
try...except solution is interesting. After further thinking, I have
to reformulate my initial question:

How do I manage to run code before my imports?

For example, I want to make sure that I can use the logging module in
the case an import fails, so I want to call logging.basicConfig()
before this particular import. Likewise, I could want to import a
module whose path is relative to an environment variable, and would
want to test if this variable is set before doing so.

I have come up with 2 solution templates :

>>> import logging
>>>
>>> main()
>>>
>>> def pre_import():
... logging.basicConfig(format='%(message)s')
>>>
>>> def import():
... global foo
... import foo
>>>
>>> def main():
... pre_import()
... import()

>>> import logging
>>> logging.basicConfig(format='%(message)s')
>>> import foo
>>>
>>> main()
>>>
>>> def main():
... pass

To me, the latter looks better, but I could be missing something. In
any case, surrounding the entire program with try...except would look
like the following?

>>> try:
... import logging
... logging.basicConfig(format='%(message)s')
... import foo
...
... main()
>>> except Exception:
... # Display simple error message
>>>
>>> def main():
... pass
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project-wide variable...

2011-06-23 Thread Guillaume Martel-Genest
On Jun 23, 9:41 am, Gnarlodious  wrote:
> Is there a way to declare a project-wide variable and use that in all
> downstream modules?
>
> -- Gnarlir

What about using an environment variable?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Wing IDE 3.2.3 released

2009-12-10 Thread Jean Guillaume Pyraksos
In article ,
 Wingware  wrote:

> http://wingware.com/downloads/wingide-101/3.2

No Cocoa version for MacOS-X ? 
Shall we have to use X11 in 2009 ? 
How come ?

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


Python IDE for MacOS-X

2010-01-18 Thread Jean Guillaume Pyraksos
What's the best one to use with beginners ?
Something with integrated syntax editor, browser of doc...
Thanks,

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


Python and Ruby

2010-01-27 Thread Jean Guillaume Pyraksos
What are the arguments for choosing Python against Ruby
for introductory programming ? Python has no provisions
for tail recursion, Ruby is going to... So what ?
Thanks,

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