Re: using python to post data to a form

2011-04-03 Thread Chris Rebert
On Sun, Apr 3, 2011 at 10:36 PM, Littlefield, Tyler  wrote:
> Hello:
> I have some data that needs to be fed through a html form to get validated
> and processed and the like. How can I use python to send data through that
> form, given a specific url? the form says it uses post, but I"m not really
> sure what the difference is.

They're different HTTP request methods:
http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods

The key upshot in this case is that GET requests place the parameters
in the URL itself, whereas POST requests place them in the body of the
request.

> would it just be:
> http://mysite.com/bla.php?foo=bar&bar=foo?

No, that would be using GET.

> If so, how do I do that with python?

Sending POST data can be done as follows (I'm changing bar=foo to
bar=qux for greater clarity):

from urllib import urlopen, urlencode

form_data = {'foo' : 'bar', 'bar' : 'qux'}
encoded_data = urlencode(form_data)
try:
# 2nd argument to urlopen() is the POST data to send, if any
f = urlopen('http://mysite.com/bla.php', encoded_data)
result = f.read()
finally:
f.close()

Relevant docs:
http://docs.python.org/library/urllib.html

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: integer multiplication

2011-04-03 Thread Paul Rubin
geremy condra  writes:
>> Does anyone know what algorithms for integer multiplication does Python use?
>> I am trying to compare it to those used by Sage as it seems like it takes
>> much longer for Python to do large integer multiplication as compared to
>> Sage (anyone know off the top of their heads?)
>> thank you
> Karatsuba multiplication, at least for large integers.

I didn't realize Python used Karatsuba.  The main issue is probably that
Python uses a straightforward portable C implementation that's not
terribly efficient, while Sage might use something like GMP, which uses
carefully tuned assembler code on many processors.  

If you look for the gmpy module, it gives you a way to use gmp from
Python.  In crypto code (lots of 1024 bit modular exponentials) I think
I found gmpy to be around 4x faster than Python longs.

I think for VERY big integers, GMP uses an FFT-based method that's
even faster than Karatsuba.
-- 
http://mail.python.org/mailman/listinfo/python-list


using python to post data to a form

2011-04-03 Thread Littlefield, Tyler

Hello:
I have some data that needs to be fed through a html form to get 
validated and processed and the like. How can I use python to send data 
through that form, given a specific url? the form says it uses post, but 
I"m not really sure what the difference is. would it just be:

http://mysite.com/bla.php?foo=bar&bar=foo?
If so, how do I do that with python?

--

Thanks,
Ty

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


Re: Guido rethinking removal of cmp from sort method

2011-04-03 Thread Terry Reedy

On 4/3/2011 1:26 AM, harrismh777 wrote:


Very interesting. Your explanations (and other excellent contributions
here) have shown an intense variation of diversity of viewpoint within
at least the comp.lang. community with regard to the Python language.


If you really want to see variation of opinion, check the archives for 
discussion of how Python does function call and return.


I take a pragmatic viewpoint toward viewpoints: they are tools, so pick 
ones that work for the particular purpose. My purpose is too make the 
language easier to learn, especially for those who have not had college 
CS/programming courses.


--
Terry Jan Reedy

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


Re: proposal to allow to set the delimiter in str.format to something other than curly bracket

2011-04-03 Thread Terry Reedy

On 4/3/2011 6:07 AM, Alia Khouri wrote:

Hi folks,

I've been using ironpython2.7 in a project, and I was generating some
csharp code when i discovered that I couldn't use use str.format
because the interference with the brackets-aplenty situation in
csharp.

In [1]: code = "class {0}Model { public bool IsModel(){ return
true; } }"

In [2]: code.format('My')


Just double the brackets, just as one doubles '\\' to get '\' in a string.

>>> "class {0}Model {{ public bool IsModel(){{ returntrue; }} 
}}".format('My')

'class MyModel { public bool IsModel(){ returntrue; } }'


--
Terry Jan Reedy

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


Re: string to path problem

2011-04-03 Thread ecu_jon
On Apr 4, 12:17 am, Chris Rebert  wrote:
> On Sun, Apr 3, 2011 at 8:30 PM, ecu_jon  wrote:
> > i am writing a basic backup program for my school. so they wanted the
> > possibility to be able to set source/destination from a config file.
> > my source/destination was fine before, i would build it up with
> > functions, like 1 that got the user-name, and put it all together with
> > os.path.join. but if they set a source in the config file to something
> > like c:\users\jon\backup  python tries to read from c:\\users\\jon\
> > \backup, and throws out a read permission (because it doesn't
> > exist ...).
>
> Please give the exact error message and full exception traceback that
> you're getting.
>
> Cheers,
> Chris
Traceback (most recent call last):
  File "I:\college\spring11\capstone-project\testing1.py", line 39, in

shutil.copy2(source1, destination)
  File "C:\Python27\lib\shutil.py", line 127, in copy2
copyfile(src, dst)
  File "C:\Python27\lib\shutil.py", line 81, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 13] Permission denied: 'c:\\users\\jon\\backup'

i have permission to c:\users\jon\*
but c:\\* obviously does not exist.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string to path problem

2011-04-03 Thread Chris Rebert
On Sun, Apr 3, 2011 at 8:30 PM, ecu_jon  wrote:
> i am writing a basic backup program for my school. so they wanted the
> possibility to be able to set source/destination from a config file.
> my source/destination was fine before, i would build it up with
> functions, like 1 that got the user-name, and put it all together with
> os.path.join. but if they set a source in the config file to something
> like c:\users\jon\backup  python tries to read from c:\\users\\jon\
> \backup, and throws out a read permission (because it doesn't
> exist ...).

Please give the exact error message and full exception traceback that
you're getting.

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


string to path problem

2011-04-03 Thread ecu_jon
i am writing a basic backup program for my school. so they wanted the
possibility to be able to set source/destination from a config file.
my source/destination was fine before, i would build it up with
functions, like 1 that got the user-name, and put it all together with
os.path.join. but if they set a source in the config file to something
like c:\users\jon\backup  python tries to read from c:\\users\\jon\
\backup, and throws out a read permission (because it doesn't
exist ...). i am not sure what to do at this point. i have look at the
docs for string, and os. . i cant os.path.join anything if they
give me an absolute path. here is a bit of the code

import os,string,fnmatch,shutil,time,getpass,md5,ConfigParser
from datetime import *
from os.path import join, getsize

config = ConfigParser.ConfigParser()
config.read("config.ini")
source = config.get("myvars", "source")
destination = config.get("myvars", "destination")
helptext = config.get("myvars", "helptext")

def weekChoice():
dateNum = datetime.now().day
if dateNum <=7:
week = 1
elif (dateNum >= 8) and (dateNum <= 14):
week = 2
elif (dateNum >= 15) and (dateNum <= 21):
week = 3
elif dateNum > 22:
week = 4
else:
print "error"
return week

def destination1():
global destination
username = getpass.getuser()
week = weekChoice()
weekstr = "week"+str(week)
destination1 = os.path.join("//mothera","jon","week1") #where //
mothera is a samba server on the network
return destination1
print "source :",source
destination = destination1()
shutil.copy2(source, destination)


here is some of config.ini
[myvars]
source:c:\users\jon\backup
destination:
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: integer multiplication

2011-04-03 Thread geremy condra
On Sun, Apr 3, 2011 at 6:41 PM, Eddie Tsay  wrote:
>
> On Sun, Apr 3, 2011 at 6:33 PM, geremy condra  wrote:
>>
>> On Sun, Apr 3, 2011 at 6:20 PM, Eddie Tsay  wrote:
>> > Does anyone know what algorithms for integer multiplication does Python
>> > use?
>> > I am trying to compare it to those used by Sage as it seems like it
>> > takes
>> > much longer for Python to do large integer multiplication as compared to
>> > Sage (anyone know off the top of their heads?)
>> > thank you
>>
>> (sorry for the double email, this was supposed to go to the list)
>>
>> Karatsuba multiplication, at least for large integers.
>>
>> Geremy Condra
>
>
> Thank you for replying to my question.
> Do you have any idea how I would be able to find how they do this
> multiplication in the python source code? I've been poking around the
> documentation and can't find the area where they outline it.
> Thank you for your reply =)
> Eddie

In the Python3 source tarball its in Objects/longobject.c. I only have
the 3.2a1 tarball on this machine, but I found the 'grade school'
method implemented in x_mul on line 2765 of that file and karatsuba
multiplication as k_mul on line 2890. YMMV depending on what version
you're looking at.

Just as a side-note, top-posting is considered a minor breach of
netiquette on python-list. I've rearranged the reply correctly here.

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


Re: integer multiplication

2011-04-03 Thread geremy condra
On Sun, Apr 3, 2011 at 6:20 PM, Eddie Tsay  wrote:
> Does anyone know what algorithms for integer multiplication does Python use?
> I am trying to compare it to those used by Sage as it seems like it takes
> much longer for Python to do large integer multiplication as compared to
> Sage (anyone know off the top of their heads?)
> thank you

(sorry for the double email, this was supposed to go to the list)

Karatsuba multiplication, at least for large integers.

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


integer multiplication

2011-04-03 Thread Eddie Tsay
Does anyone know what algorithms for integer multiplication does Python use?
I am trying to compare it to those used by Sage as it seems like it takes
much longer for Python to do large integer multiplication as compared to
Sage (anyone know off the top of their heads?)

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


Re: Looking for ideas on controlling python module loading

2011-04-03 Thread Chris Angelico
On Mon, Apr 4, 2011 at 10:44 AM, Nathan Coulson  wrote:
> Hello, I am working on a client/server program (game) that uses C w/
> an embedded python interpreter, that uses python to script what
> objects do in the game.   (primarily a C environment)
>
> I was wondering if it is possible to control what modules get loaded
> (or not).  perhaps by determining if the hash of the local file
> matches a hash provided by the server.
>
> I was also wondering, if you could construct a module, without a .py
> file, and define functions and variables.

You certainly can. I assume your idea is that you write the C code,
but someone else can write the Python, and you want to lock it down?
That's what I have in this system at work, and it's fairly easy to
sandbox.

(Note: This uses Python 2. Some things may be different in Python 3.)

There's three easy ways to set up the global dictionary:
1) py_globals=PyDict_New(); //Completely empty, not very useful. You
don't even get stuff like 'True' unless you manually add them.
2) py_globals=PyModule_GetDict(PyImport_AddModule("__main__")); //This
gives an environment similar to IDLE. Fairly wide open.
3) py_globals=PyModule_GetDict(PyImport_AddModule("__builtin__"));
//Restricted environment.

Go with the third option and you get easy control over what the Python
code can do. I then disable a number of functions with
PyDict_DelItemString (for instance, input and raw_input - my program
has no console); you could alternatively replace those symbols with
something of your own (maybe replace raw_input with something that
reads from the socket??), or leave them if they're not going to be a
problem.

What I did was to disable importing altogether, and import a specific
set of modules (math, string, and a couple more) manually. That
ensures that, no matter what, the sandbox is safe; but this might not
be well suited to your situation.

As to creating modules - I've never done that per se, but it's easy
enough to create a Py-callable function inside your C code. In what I
do, it's easier to simply insert that into the globals dictionary,
making it a top-level function:

PyMethodDef fnc={"functionname",functionname,1,"Function Description"};
PyDict_SetItemString(py_globals,"functionname",PyCFunction_New(&fnc,0));

Note by the way that I "cheat" the refcounting a bit with this
initialization code, since it is only ever called once and then the
global state is maintained through the whole program. If you need
multiple states or need to clean up the mess at some point, you may
need to check the refcounts to make sure none are leaked.

Hope that's of value!

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


Looking for ideas on controlling python module loading

2011-04-03 Thread Nathan Coulson
Hello, I am working on a client/server program (game) that uses C w/
an embedded python interpreter, that uses python to script what
objects do in the game.   (primarily a C environment)

I was wondering if it is possible to control what modules get loaded
(or not).  perhaps by determining if the hash of the local file
matches a hash provided by the server.

I was also wondering, if you could construct a module, without a .py
file, and define functions and variables.


-- 
Nathan Coulson (conathan)
--
Location: British Columbia, Canada
Timezone: PST (-8)
Webpage: http://www.nathancoulson.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Light weight IDE like pywin for os x 10.6

2011-04-03 Thread python
I have looked a while for this answer.  Sorry if it right before me.

I have move from Windows to os x.  The thing I miss most is pywin.
I know you can purchase or download full IDE's for python or even use
Eclipse.   I really liked the ability to switch from interactive
interpreter to editor easily.  The autocompletion is very helpful so
idle does not quite cut it for me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python users in Stavanger, Norway?

2011-04-03 Thread Rafe Kettler
On Apr 3, 3:32 am, Austin Bingham  wrote:
> Hei!
>
> I'm a Python developer in Stavanger, Norway looking for other Python
> users/developers/etc. who might be interested in starting a local user
> group. Anyone interested? This group might actually evolve into a
> general programming/computer group, depending on the mix of people,
> but I think that's probably a good thing.
>
> I know there are a lot of computer types in the area, but there
> doesn't seem to be much of a "community". I'd like to change that if
> we can, so let me know if you're interested.
>
> Austin

In addition to trying here, try #python on Freenode. You're probably
more likely to find users there. You may also want to consider
expanding the geographic area if you don't have much luck (perhaps for
the region of Norway that Stavanger is in).

Rafe (also not from Stavanger)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CPU

2011-04-03 Thread Nobody
On Sun, 03 Apr 2011 10:15:34 -0700, John Nagle wrote:

>  Note that if you run out of return point stack, or parameter
> stack, you're stuck.  So there's a hardware limit on call depth.
> National Semiconductor once built a CPU with a separate return
> point stack with a depth of 20.  Big mistake.

The 8-bit PIC microcontrollers have a separate return stack. The PIC10 has
a 2-level stack, the PIC16 has 8 levels, and the PIC18 has 31 levels.

But these chips range from 16 bytes of RAM and 256 words of flash for a
PIC10, through 64-256 bytes of RAM and 1-4K words of flash for a PIC16, up
to 2KiB of RAM and 16K words of flash for a PIC18, so you usually run out
of something else long before the maximum stack depth becomes an issue.

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


Re: Guido rethinking removal of cmp from sort method

2011-04-03 Thread geremy condra
On Sun, Apr 3, 2011 at 3:21 AM, Steven D'Aprano
 wrote:
> On Sun, 03 Apr 2011 16:34:34 +1000, Brian Quinlan wrote:
>
>> On 3 Apr 2011, at 16:22, geremy condra wrote:
>>> I think we're talking at cross purposes. The point I'm making is that
>>> there are lots of issues where popularity as a third party module isn't
>>> really a viable test for whether a feature is sufficiently awesome to
>>> be in core python. As part of determining whether I thought it was
>>> appropriate in this case I essentially just asked myself whether any of
>>> the really good and necessary parts of Python would fail to be
>>> readmitted under similar circumstances, and I think the answer is that
>>> very few would come back in. To me, that indicates that this isn't the
>>> right way to address this issue, although I admit that I lack any solid
>>> proof to base that conclusion on.
>>
>> This has been discussed a few times on python-dev. I think that most
>> developers acknowledge that small-but-high-utility modules would not
>> survive outside of the core because people would simple recreate them
>> rather than investing the time to find, learn and use them.
>
> That's certainly true for pure Python code, but for a C extension, the
> barrier to Do It Yourself will be much higher for most Python coders.

I don't think people will work around it in C. I think they'll
grudgingly accept a slow and kludgy python workaround, and more to the
point I think they would do that with a vast majority of features at
this scale. That's why I say this isn't a good test here- because you
could apply it to a great feature or a terrible feature and with
overwhelming probability have them fail in both cases.

> On the other hand, for a pure Python function or class, you could stick
> it on ActiveState's Python cookbook and get some imperfect measure of
> popularity and/or usefulness from the comments and votes there.

Frankly, I have little trust in this as a measure of popularity. Even
PyPI isn't a great indicator, and the numbers you get off of
ActiveState are almost certain to be way, way noisier.

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


Re: [Twisted-Python] [ANNOUNCE] Twisted 11.0.0 Released

2011-04-03 Thread Laurens Van Houtven
Today is indeed a very, very good day.

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


[ANNOUNCE] Twisted 11.0.0 Released

2011-04-03 Thread Jessica McKellar
 PAS MAINTENANT CHEF! CHUIS EN TRAIN DE BRANCHER LE REACTEUR

On behalf of Twisted Matrix Laboratories, I am honored to announce the
release of Twisted 11.0.0.

Highlights include:

 * a new templating system in Twisted Web, "twisted.web.template",
derived from Divmod Nevow.
 * improved behavior of subprocess spawning on FreeBSD.
 * the 'twistd mail' plugin now uses the endpoints API, providing a
more consistent command line and compatibility with endpoint plugins.
 * twisted.plugin no longer emits a confusing traceback when it can't
write a cache file.

and numerous other bugfixes and documentation improvements. For more
information, see the NEWS file.

Download it now from:

    

or install the 'Twisted' package from PyPI.

Many thanks to Glyph Lefkowitz and Jean-Paul Calderone for
sanity-checking the pre-releases and release, and to the enthusiastic
PyCon 2011 sprinters who annihilated dozens of tickets. Thanks to
*everyone* who contributed tickets, patches, documentation, reviews,
buildbots, feedback, and assistance to fellow users and developers
leading up to this release. It is truly a group effort.



is a testament to how much work was done in March alone.

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


Re: Python CPU

2011-04-03 Thread John Nagle

On 4/3/2011 8:44 AM, Werner Thie wrote:

You probably heard of the infamous FORTH chips like the Harris RTX2000,
or ShhBoom, which implemented a stack oriented very low power design
before there were FPGAs in silicon. To my knowledge the RTX2000 is still
used for space hardened application and if I search long enough I might
fine the one I had sitting in my cellar.

The chip was at that time so insanely fast that it could produce video
signals with FORTH programs driving the IO pins. Chuck Moore, father of
FORTH developed the chip on silicon in FORTH itself.


He did version 1, which had a broken integer divide operation.
(Divisors which were odd numbers produced wrong answers. Really.)
I came across one of those in a demo setup at a surplus store in
Silicon Valley, driving the CRT and with Moore's interface that
did everything with chords on three buttons.


Due to the fact, that the instruction sets of a FORTH machine, being a
very general stack based von Neumann system, I believe that starting
with an RTX2000 (which should be available in VHDL) one could quite fast
be at a point where things make sense, meaning not going for the
'fastest' ever CPU but for the advantage of having a decent CPU
programmable in Python sitting on a chip with a lot of hardware available.


Willow Garage has VHDL available for a Forth CPU.  It's only 200
lines.

The Forth CPUs have three separate memories - RAM, Forth stack,
and return stack. All three are accessed on each cycle.  Back before
microprocessors had caches, this was a win over traditional CPUs,
where memory had to be accessed sequentially for those functions.
Once caches came in, it was a lose.

It's interesting that if you wanted to design a CPU for Googles's
"nativeclient" approach for executing native code in the browser,
a separate return point stack would be a big help.  Google's
"nativeclient" system protects return points, so that you can tell,
from the source code, all the places control can go.  This is
a protection against redirection via buffer overflows, something
that's possible on x86 because the return points and other data
share the same stack.

Note that if you run out of return point stack, or parameter
stack, you're stuck.  So there's a hardware limit on call depth.
National Semiconductor once built a CPU with a separate return
point stack with a depth of 20.  Big mistake.

(All of this is irrelevant to Python, though. Most of Python's
speed problems come from spending too much time looking up attributes
and functions in dictionaries.)

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


Re: Python users in Stavanger, Norway?

2011-04-03 Thread David Boddie
On Sunday 03 April 2011 09:32, Austin Bingham wrote:

> I'm a Python developer in Stavanger, Norway looking for other Python
> users/developers/etc. who might be interested in starting a local user
> group. Anyone interested? This group might actually evolve into a
> general programming/computer group, depending on the mix of people,
> but I think that's probably a good thing.
> 
> I know there are a lot of computer types in the area, but there
> doesn't seem to be much of a "community". I'd like to change that if
> we can, so let me know if you're interested.

If you manage to get something started, please update the list on the
Python Wiki:

  http://wiki.python.org/moin/LocalUserGroups#Norway

David (not in Stavanger)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python CPU

2011-04-03 Thread Werner Thie
You probably heard of the infamous FORTH chips like the Harris RTX2000, 
or ShhBoom, which implemented a stack oriented very low power design 
before there were FPGAs in silicon. To my knowledge the RTX2000 is still 
used for space hardened application and if I search long enough I might 
fine the one I had sitting in my cellar.


The chip was at that time so insanely fast that it could produce video 
signals with FORTH programs driving the IO pins. Chuck Moore, father of 
FORTH developed the chip on silicon in FORTH itself.


Due to the fact, that the instruction sets of a FORTH machine, being a 
very general stack based von Neumann system, I believe that starting 
with an RTX2000 (which should be available in VHDL) one could quite fast 
be at  a point where things make sense, meaning not going for the 
'fastest' ever CPU but for the advantage of having a decent CPU 
programmable in Python sitting on a chip with a lot of hardware available.


Another thing worth to mention in this context is for sure the work 
available on http://www.myhdl.org/doku.php.


Werner

On 4/3/11 3:46 AM, Dan Stromberg wrote:


On Sat, Apr 2, 2011 at 5:10 PM, Gregory Ewing
mailto:greg.ew...@canterbury.ac.nz>> wrote:

Brad wrote:

I've heard of Java CPUs. Has anyone implemented a Python CPU in VHDL
or Verilog?


Not that I know of.

I've had thoughts about designing one, just for the exercise.

It's doubtful whether such a thing would ever be of practical
use. Without as much money as Intel has to throw at CPU
development, it's likely that a Python chip would always be
slower and more expensive than an off-the-shelf CPU running
a tightly-coded interpreter.

It could be fun to speculate on what a Python CPU might
look like, though.


One with the time and inclination could probably do a Python VM in an
FPGA, no?

Though last I heard, FPGA's weren't expected to increase in performance
as fast as general-purpose CPU's.



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


[Fwd: Re: about Pyclutter]

2011-04-03 Thread craf
Thanks for the answer.

Regards.

Cristian
- Mensaje reenviado 
> De: Blockheads Oi Oi 
> Para: python-list@python.org
> Asunto: Re: about Pyclutter
> Fecha: Sun, 03 Apr 2011 11:41:32 +0100
> 
> On 02/04/2011 17:54, craf wrote:
> > Hi
> >
> > Does anyone know how mature is Pyclutter?.
> >
> > Regards
> >
> > Cristian Abarzúa
> >
> 
> I don't kow about mature but from 
> http://wiki.clutter-project.org/wiki/PyClutter.
> 
> "WARNING: PyClutter only covers the 1.0 API, and it is going to be 
> deprecated in favour of introspection-based bindings using PyGObject."
> 
> HTH.
> 
> Mark L.
> 


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


[Fwd: Re: Another location of the PyGTK tutorial]

2011-04-03 Thread craf
¡Thank you very much Dotan!

Regards.

Cristian
- Mensaje reenviado 
> De: Dotan Cohen 
> Para: craf 
> Cc: Python Ingles 
> Asunto: Re: Another location of the PyGTK tutorial
> Fecha: Sun, 3 Apr 2011 13:40:35 +0300
> 
> http://gitorious.org/pygtk-tutorial
> 
> On Fri, Apr 1, 2011 at 21:03, craf  wrote:
> > Hi.
> >
> > Anyone know if the pygtk tutorial that was in this direction
> > http://www.learnpygtk.org/pygtktutorial/index.html,  can be located
> > elsewhere.
> >
> > Regards.
> >
> > Cristian
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
> 
> 
> 
> -- 
> Dotan Cohen
> 
> http://gibberish.co.il
> http://what-is-what.com


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


Re: TypeError: iterable argument required

2011-04-03 Thread eryksun ()
On Saturday, April 2, 2011 12:26:18 PM UTC-4, Νικόλαος Κούρας wrote:
> Hello, after inserting this line if "@" in mail and comment not in
> ("Σχολιάστε ή ρωτήστε με σχετικά", ""):
> 
> iam getting the following error which i dont understand
> 
> **
> 163 # insert guest comments into database if form was
> submitted
>   164 if "@" in mail and comment not in ("Σχολιάστε ή ρωτήστε
> με σχετικά", ""):
>   165 try:
>   166 cursor.execute( '''INSERT INTO
> users(mail, comment) VALUES(%s, %s)''', (mail, comment) )
> mail = None, comment = None
> 
> TypeError: iterable argument required
>   args = ('iterable argument required',)

Here's how I parse what you've written so far:

INVALID_COMMENTS = ("Σχολιάστε ή ρωτήστεμε σχετικά", "")
SQL_COMMENT_FORM = "INSERT INTO users(mail, comment) VALUES(%s, %s)"

# insert guest comments into database if form was submitted
mail = form.getvalue('mail')
comment = form.getvalue('comment')
if "@" in mail and comment not in INVALID_COMMENTS:
try:
cursor.execute(SQL_COMMENT_FORM % (mail, comment))
except MySQLdb.Error as e:
print("Error %d: %s" % (e.args[0], e.args[1]))
else:
mail = comment = None
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: proposal to allow to set the delimiter in str.format to something other than curly bracket

2011-04-03 Thread Alia Khouri
On Apr 3, 1:53 pm, Corey Richardson  wrote:
> On 04/03/2011 06:07 AM, Alia Khouri wrote:
>
> > Hi folks,
>
> > I've been using ironpython2.7 in a project, and I was generating some
> > csharp code when i discovered that I couldn't use use str.format
> > because the interference with the brackets-aplenty situation in
> > csharp.
>
> Roll your ownhttp://docs.python.org/library/string.html#string.Formatter
>

(-:

Thanks for the tip, looks I can subclass string.Template to get what I
need.

Kicking myself for posting too early...

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


Re: better way to do this in python

2011-04-03 Thread Mag Gam
Thanks for the responses.


Basically, I have a large file with this format,

Date INFO username command srcipaddress filename


I would like to do statistics on:
total number of usernames and who they are
username and commands
username and filenames
unique source ip addresses
unique filenames

Then I would like to bucket findings with days (date).

Overall, I would like to build a log file analyzer.



On Sat, Apr 2, 2011 at 10:59 PM, Dan Stromberg  wrote:
>
> On Sat, Apr 2, 2011 at 5:24 PM, Chris Angelico  wrote:
>>
>> On Sun, Apr 3, 2011 at 9:58 AM, Mag Gam  wrote:
>> > I suppose I can do something like this.
>> > (pseudocode)
>> >
>> > d={}
>> > try:
>> >  d[key]+=1
>> > except KeyError:
>> >  d[key]=1
>> >
>> >
>> > I was wondering if there is a pythonic way of doing this? I plan on
>> > doing this many times for various files. Would the python collections
>> > class be sufficient?
>>
>> I think you want collections.Counter. From the docs: "Counter objects
>> have a dictionary interface except that they return a zero count for
>> missing items instead of raising a KeyError".
>>
>> ChrisA
>
> I realize you (Mag) asked for a Python solution, but since you mention
> awk... you can also do this with "sort < input | uniq -c" - one line of
> "code".  GNU sort doesn't use as nice an algorithm as a hashing-based
> solution (like you'd probably use with Python), but for a sort, GNU sort's
> quite good.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: proposal to allow to set the delimiter in str.format to something other than curly bracket

2011-04-03 Thread Corey Richardson
On 04/03/2011 06:07 AM, Alia Khouri wrote:
> Hi folks,
> 
> I've been using ironpython2.7 in a project, and I was generating some
> csharp code when i discovered that I couldn't use use str.format
> because the interference with the brackets-aplenty situation in
> csharp.
> 

Roll your own http://docs.python.org/library/string.html#string.Formatter

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


Re: about Pyclutter

2011-04-03 Thread Blockheads Oi Oi

On 02/04/2011 17:54, craf wrote:

Hi

Does anyone know how mature is Pyclutter?.

Regards

Cristian Abarzúa



I don't kow about mature but from 
http://wiki.clutter-project.org/wiki/PyClutter.


"WARNING: PyClutter only covers the 1.0 API, and it is going to be 
deprecated in favour of introspection-based bindings using PyGObject."


HTH.

Mark L.

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


Re: Another location of the PyGTK tutorial

2011-04-03 Thread Dotan Cohen
http://gitorious.org/pygtk-tutorial

On Fri, Apr 1, 2011 at 21:03, craf  wrote:
> Hi.
>
> Anyone know if the pygtk tutorial that was in this direction
> http://www.learnpygtk.org/pygtktutorial/index.html,  can be located
> elsewhere.
>
> Regards.
>
> Cristian
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another location of the PyGTK tutorial

2011-04-03 Thread Dotan Cohen
http://gitorious.org/pygtk-tutorial

On Sat, Apr 2, 2011 at 19:53, craf  wrote:
> Hi.
>
> Anyone know if the pygtk tutorial that was in this direction
> http://www.learnpygtk.org/pygtktutorial/index.html,  can be located
> elsewhere.
>
> Regards.
>
> Cristian
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guido rethinking removal of cmp from sort method

2011-04-03 Thread Steven D'Aprano
On Sun, 03 Apr 2011 16:34:34 +1000, Brian Quinlan wrote:

> On 3 Apr 2011, at 16:22, geremy condra wrote:
>> I think we're talking at cross purposes. The point I'm making is that
>> there are lots of issues where popularity as a third party module isn't
>> really a viable test for whether a feature is sufficiently awesome to
>> be in core python. As part of determining whether I thought it was
>> appropriate in this case I essentially just asked myself whether any of
>> the really good and necessary parts of Python would fail to be
>> readmitted under similar circumstances, and I think the answer is that
>> very few would come back in. To me, that indicates that this isn't the
>> right way to address this issue, although I admit that I lack any solid
>> proof to base that conclusion on.
> 
> This has been discussed a few times on python-dev. I think that most
> developers acknowledge that small-but-high-utility modules would not
> survive outside of the core because people would simple recreate them
> rather than investing the time to find, learn and use them.

That's certainly true for pure Python code, but for a C extension, the 
barrier to Do It Yourself will be much higher for most Python coders.

On the other hand, for a pure Python function or class, you could stick 
it on ActiveState's Python cookbook and get some imperfect measure of 
popularity and/or usefulness from the comments and votes there.



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


proposal to allow to set the delimiter in str.format to something other than curly bracket

2011-04-03 Thread Alia Khouri
Hi folks,

I've been using ironpython2.7 in a project, and I was generating some
csharp code when i discovered that I couldn't use use str.format
because the interference with the brackets-aplenty situation in
csharp.

In [1]: code = "class {0}Model { public bool IsModel(){ return
true; } }"

In [2]: code.format('My')
---
KeyError  Traceback (most recent call
last)

KeyError: ' public bool IsModel(){ return true; } '

Please note I had no trouble with the trusty old % interpolation
method.

Now given that using str.format in this use case (code generation) is
equally difficult for other bracketed languages, and that str.format
is supposed to eventually become 'best-practice' for python string
formatting, can I get some feedback on a proposal that for the odd
case when brackets don't cut it, there is a way to redefine the
delimiter for str.format so that one could do something like this:

str.format_delimiter = ("[[", "]]")

and we could write something like this:

In [1]: code = "class [[0]]Model { public bool IsModel(){ return
true; } }"
In [2]: code.format('My')
Out[3]: 'class MyModel { public bool IsModel(){ return true; } }'


Please give your +N or -N and reasons below.

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


about Pyclutter

2011-04-03 Thread craf
Hi

Does anyone know how mature is Pyclutter?.

Regards

Cristian Abarzúa 

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


Another location of the PyGTK tutorial

2011-04-03 Thread craf
Hi.

Anyone know if the pygtk tutorial that was in this direction
http://www.learnpygtk.org/pygtktutorial/index.html,  can be located
elsewhere.

Regards.

Cristian

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


Another location of the PyGTK tutorial

2011-04-03 Thread craf
Hi.

Anyone know if the pygtk tutorial that was in this direction
http://www.learnpygtk.org/pygtktutorial/index.html,  can be located
elsewhere.

Regards.

Cristian

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


Re: Python CPU

2011-04-03 Thread Paul Rubin
John Nagle  writes:
> The Forth chips were cute, and got more done with fewer gates than
> almost anything else.  But that didn't matter for long.
> Willow Garage has a custom Forth chip they use in their Ethernet
> cameras, but it's really a FPGA.

You can order 144-core Forth chips right now,

   http://greenarrays.com/home/products/index.html

They are asynchronous cores running at around 700 mhz, so you get an
astounding amount of raw compute power per watt and per dollar.  But for
me at least, it's not that easy to figure out applications where their
weird architecture fits well.
-- 
http://mail.python.org/mailman/listinfo/python-list


ami&bigchurch messages

2011-04-03 Thread asif m.asif
http://123maza.com/75/offer210/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem regarding returning list

2011-04-03 Thread Ian Kelly
On Sun, Apr 3, 2011 at 1:12 AM, sl33k  wrote:
> I am trying to return a list of items modified with each item also
> showing like the number of modifications.
>
> Returning a list of user modified items was done easily but I would
> also like to display the item modified by the user and the
> modifications of that particular item.
> Typical way it coould be displayed like is,
> Modified item: No of modifications to it
>
> E.g. sl33k: 3
>
> Some background of the base class methods used:
>
> list_revisions() - gets the list of ints of the all modification of a
> particular item
> get_revision() - given the modification int, it gets the specific
> modified item.
> item.name gives the name of the item
> The method takes for argument the list of items.
>
> I start by declaring a set() of the total modified items. Using for
> loop in the items and in the for loop for particular `int`
> modification of it, I collect the modified item.
> But, I get stuck around when I have to collect the no of modifications
> for one. The set is returned as a list to a template engine for the
> display.
>
> So, I would like to collect for each item, its no of modifications.
> How would I go about doing this? How would i return it with list of
> modified items tp display the above shown example?
>
> Any pointers will be much appreciated.

Instead of a set, you should use a dict, where the keys are the items
and the values are the numbers of modifications.  Your return value
would either be the dict itself or the result of dict.items().

If you're using a recent enough version of Python, you might also have
a look at the collections.Counter class, which is a dict subclass that
is specialized for counting things.

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


Re: Python CPU

2011-04-03 Thread Carl Banks
It'd be kind of hard.  Python bytecode operates on objects, not memory slots, 
registers, or other low-level entities like that.  Therefore, in order to 
implement a "Python machine" one would have to implement the whole object 
system in the hardware, more or less.

So it'd be possible but not too practical or likely.


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


Python users in Stavanger, Norway?

2011-04-03 Thread Austin Bingham
Hei!

I'm a Python developer in Stavanger, Norway looking for other Python
users/developers/etc. who might be interested in starting a local user
group. Anyone interested? This group might actually evolve into a
general programming/computer group, depending on the mix of people,
but I think that's probably a good thing.

I know there are a lot of computer types in the area, but there
doesn't seem to be much of a "community". I'd like to change that if
we can, so let me know if you're interested.

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


Re: Problem regarding returning list

2011-04-03 Thread sl33k
On Apr 3, 3:12 am, sl33k  wrote:
> I am trying to return a list of items modified with each item also
> showing like the number of modifications.
>
> Returning a list of user modified items was done easily but I would
> also like to display the item modified by the user and the
> modifications of that particular item.
> Typical way it coould be displayed like is,
> Modified item: No of modifications to it
>
> E.g. sl33k: 3
>
> Some background of the base class methods used:
>
> list_revisions() - gets the list of ints of the all modification of a
> particular item
> get_revision() - given the modification int, it gets the specific
> modified item.
> item.name gives the name of the item
> The method takes for argument the list of items.
>
> I start by declaring a set() of the total modified items. Using for
> loop in the items and in the for loop for particular `int`
> modification of it, I collect the modified item.
> But, I get stuck around when I have to collect the no of modifications
> for one. The set is returned as a list to a template engine for the
> display.
>
> So, I would like to collect for each item, its no of modifications.
> How would I go about doing this? How would i return it with list of
> modified items tp display the above shown example?
>
> Any pointers will be much appreciated.
>
> Code:
>
> def foo(items):
>
> modified_items = set()
>     rev_count = []
>     for item in items:
>         item_name = item.name
>         revnos = item.list_revisions()
>         for revno in revnos:
>             revision = item.get_revision(revno)
>             if modications userid == loggedin users userid:
>                 contribution_items.add(item_name)
>
>           # How do i collect revisions here
>
> return list(contribution_items)

I messed up with naming.
It should be
contribution_items = set()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guido rethinking removal of cmp from sort method

2011-04-03 Thread harrismh777

geremy condra wrote:

Something to consider is that OOP philosophy is technically one of the most
>  aesthetic concepts in all of computer science--- with pure functional
>  programming (haskel, erlang) as a close second...

I like how you inserted the word 'technically' in there to give this
totally unsubstantiated assertion apparent weight.


You picked up on that, did you?:-))


I just solved this little difficulty in my own system  ~/bin/

   python -> /home/mydir/local/python2.7/bin/python2

   anaconda -> /home/mydir/local/python3.2/bin/python3

;)


kind regards,
m harris
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python CPU

2011-04-03 Thread John Nagle

On 4/2/2011 9:01 PM, Steven D'Aprano wrote:

There were also Forth chips, which let you run Forth in hardware. I
believe they were much faster than Forth in software, but were killed by
the falling popularity of Forth.


The Forth chips were cute, and got more done with fewer gates than
almost anything else.  But that didn't matter for long.
Willow Garage has a custom Forth chip they use in their Ethernet
cameras, but it's really a FPGA.

A tagged machine might make Python faster.  You could have
unboxed ints and floats, yet still allow values of other types,
with the hardware tagging helping with dispatch.   But it probably
wouldn't help all that much.  It didn't in the LISP machines.

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


Problem regarding returning list

2011-04-03 Thread sl33k
I am trying to return a list of items modified with each item also
showing like the number of modifications.

Returning a list of user modified items was done easily but I would
also like to display the item modified by the user and the
modifications of that particular item.
Typical way it coould be displayed like is,
Modified item: No of modifications to it

E.g. sl33k: 3

Some background of the base class methods used:

list_revisions() - gets the list of ints of the all modification of a
particular item
get_revision() - given the modification int, it gets the specific
modified item.
item.name gives the name of the item
The method takes for argument the list of items.

I start by declaring a set() of the total modified items. Using for
loop in the items and in the for loop for particular `int`
modification of it, I collect the modified item.
But, I get stuck around when I have to collect the no of modifications
for one. The set is returned as a list to a template engine for the
display.

So, I would like to collect for each item, its no of modifications.
How would I go about doing this? How would i return it with list of
modified items tp display the above shown example?

Any pointers will be much appreciated.

Code:

def foo(items):

modified_items = set()
rev_count = []
for item in items:
item_name = item.name
revnos = item.list_revisions()
for revno in revnos:
revision = item.get_revision(revno)
if modications userid == loggedin users userid:
contribution_items.add(item_name)

  # How do i collect revisions here

return list(contribution_items)
-- 
http://mail.python.org/mailman/listinfo/python-list