Re: PostgreSQL vs MySQL (was Re: How to handle sockets - easily?)

2011-03-17 Thread J Peyret
On Mar 16, 10:19 am, a...@pythoncraft.com (Aahz) wrote:
> In article ,

> >always recommend people to use PostgreSQL, though; which is superior in
> >almost every way, especially the C client library and the wire protocol.)
>
> Can you point at a reference for the latter?  I have been trying to
> convince my company that PG is better than MySQL.
> --

Well, my $.02 worth is that, about 3 yrs ago, on 5.0x-5.1x, I was
truly appalled by the sheer level of stupidity displayed by MySQL's
handling of a moderately complex UPDATE SQL query with a correlated
subquery.

(Let's say this was a 7 out of 10 complexity, with your standard
selects being 1-3 max and a nightmare update query with all sorts of
correlated subqueries would be a 9.  I am first of all a database
programmer, so queries are my world).

Not only did MySQL mangle the query because it didn't understand what
I was asking, it thrashed the data during the update and committed
it.  And, when I reviewed the query once again, I found I had
mismatched parentheses, so it wasn't even syntaxically correct.  Truly
scary.

DB2 + SQLBase punted for years on correlated subqueries  Ex:  "update
ORDERS where x=y and exists (select 1 from ORDERS where )".  The DB2 engine doesn't know how to handle them, so it
tells you to get lost.

MySQL is not smart enough to recognize it's over its head and instead
makes a best effort.  To me it looks like a database that will get you
80% there and steadfastly refuse the last 20%, assuming you need
really clever queries.  PG was much cleaner in behavior, though a pain
to install, especially on Windows.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating RAW sockets

2011-03-17 Thread moijes12
On Mar 18, 6:20 am, Nobody  wrote:
> On Wed, 16 Mar 2011 23:50:03 -0700, moijes12 wrote:
> > Now,please can someone guide(as in what should I read and NOT as in
> > give me the code) me in decoding the IP header of packets using python
> > 3.0.1.
>
> The "struct" module is the usual approach for decoding binary data
> structures. Fields which aren't whole bytes/words will need to
> be extracted manually using >> and &.
>
> In case you don't already have it, the layout of an IPv4 header can be
> found at:
>
>        http://en.wikipedia.org/wiki/IPv4#Header
>
> Remember that TCP/IP uses big-endian format.

thanks guys
Moijes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Abend with cls.__repr__ = cls.__str__ on Windows.

2011-03-17 Thread J Peyret
On Mar 17, 9:37 pm, Terry Reedy  wrote:
> On 3/17/2011 10:00 PM, Terry Reedy wrote:
>
> > On 3/17/2011 8:24 PM, J Peyret wrote:
> >> This gives a particularly nasty abend in Windows - "Python.exe has
> >> stopped working", rather than a regular exception stack error. I've
> >> fixed it, after I figured out the cause, which took a while, but maybe
> >> someone will benefit from this.
>
> >> Python 2.6.5 on Windows 7.
>
> >> class Foo(object):
> >> pass
>
> >> Foo.__repr__ = Foo.__str__ # this will cause an abend.
>
> > 2.7.1 and 3.2.0 on winxp, no problem, interactive intepreter or IDLE
> > shell. Upgrade?
>
> To be clear, the above, with added indent, but with extra fluff (fixes)
> removed, is exactly what I ran. If you got error with anything else,
> please say so. Described behavior for legal code is a bug. However,
> unless a security issue, it would not be fixed for 2.6.
>
> --
> Terry Jan Reedy

Nope, that is it.  No need to upgrade, nor is there any urgency.  I
was just surprised to see it fail so brutally, is all.  I've only
encountered 2 or 3 core Python bugs at that level in about 13 yrs of
coding in it, so thought I'd post it, especially as it is so easy to
replicate.

Txs for your help

I actually have another really weird behavior in this program, but
haven't figured out yet what causes it so it is hard to tell if it's
an error on my part or another system bug.  I'll post it if I can
isolate a system error.

FWIW, what I am doing is using Configparser to assemble a bunch of
classes together to provide a reporting/diffing engine for database
comparisons.  The object compositions are all defined in an .ini file.

I've found Python + ini files are a great match for creating truly
flexible programs.  SQL queries, template strings and regular
expression patterns can be stored in the ini file and are easy to
modify without touching the core python code.  Pass a different ini
file => different behavior.  Xml is overkill for this and plays really
badly with relational <,> operators.

This is the next step for me, defining mostly separate classes and
assembling and initializing them based on ini file configuration info.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Abend with cls.__repr__ = cls.__str__ on Windows.

2011-03-17 Thread Terry Reedy

On 3/17/2011 10:00 PM, Terry Reedy wrote:

On 3/17/2011 8:24 PM, J Peyret wrote:

This gives a particularly nasty abend in Windows - "Python.exe has
stopped working", rather than a regular exception stack error. I've
fixed it, after I figured out the cause, which took a while, but maybe
someone will benefit from this.

Python 2.6.5 on Windows 7.

class Foo(object):
pass

Foo.__repr__ = Foo.__str__ # this will cause an abend.


2.7.1 and 3.2.0 on winxp, no problem, interactive intepreter or IDLE
shell. Upgrade?


To be clear, the above, with added indent, but with extra fluff (fixes) 
removed, is exactly what I ran. If you got error with anything else, 
please say so. Described behavior for legal code is a bug. However, 
unless a security issue, it would not be fixed for 2.6.


--
Terry Jan Reedy

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


Re: Abend with cls.__repr__ = cls.__str__ on Windows.

2011-03-17 Thread Steven D'Aprano
On Thu, 17 Mar 2011 17:24:36 -0700, J Peyret wrote:

> This gives a particularly nasty abend in Windows - "Python.exe has
> stopped working", rather than a regular exception stack error.  I've
> fixed it, after I figured out the cause, which took a while, but maybe
> someone will benefit from this.
> 
> Python 2.6.5 on Windows 7.

I get the same behaviour on Python 2.6, 2.7 and 3.1 under Linux: the 
Python process hangs until killed manually.


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


Re: Abend with cls.__repr__ = cls.__str__ on Windows.

2011-03-17 Thread Terry Reedy

On 3/17/2011 8:24 PM, J Peyret wrote:

This gives a particularly nasty abend in Windows - "Python.exe has
stopped working", rather than a regular exception stack error.  I've
fixed it, after I figured out the cause, which took a while, but maybe
someone will benefit from this.

Python 2.6.5 on Windows 7.

class Foo(object):
 pass

Foo.__repr__ = Foo.__str__   # this will cause an abend.


2.7.1 and 3.2.0 on winxp, no problem, interactive intepreter or IDLE 
shell. Upgrade?



--
Terry Jan Reedy

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


Re: creating RAW sockets

2011-03-17 Thread Nobody
On Wed, 16 Mar 2011 23:50:03 -0700, moijes12 wrote:

> Now,please can someone guide(as in what should I read and NOT as in
> give me the code) me in decoding the IP header of packets using python
> 3.0.1.

The "struct" module is the usual approach for decoding binary data
structures. Fields which aren't whole bytes/words will need to
be extracted manually using >> and &.

In case you don't already have it, the layout of an IPv4 header can be
found at:

http://en.wikipedia.org/wiki/IPv4#Header

Remember that TCP/IP uses big-endian format.

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


Re: Fitting polynomial curve

2011-03-17 Thread Dan Stromberg
On Thu, Mar 17, 2011 at 5:44 PM, Astan Chee  wrote:

>
> On Thu, Mar 17, 2011 at 5:09 PM, Terry Reedy  wrote:
>
>> Look at scipy.
>>
>
> Thanks for the info. I realized I made some mistakes. Anyway, what I'm
> trying to do is in maya (python), fit selected vertices on a curve. Here is
> what I have so far:
>
> ...

>
> But this only works for 2D (x,z-axis). Is it possible to make it work at 3
> by combining them or doing (x,y) and (x,z) and somehow colate (average?) the
> results? Is there a formula for combining the results?
> Thanks again for any help or suggestions
>

Maybe this?

http://code.google.com/p/pythonequations/downloads/list

Or google for "three dimensional curve fitting".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PostgreSQL vs MySQL

2011-03-17 Thread Aahz
In article <87bp1a3g59@benfinney.id.au>,
Ben Finney   wrote:
>a...@pythoncraft.com (Aahz) writes:
>
>>>(I always recommend people to use PostgreSQL, though; which is
>>>superior in almost every way, especially the C client library and the
>>>wire protocol.)
>>
>> Can you point at a reference for the latter?  I have been trying to
>> convince my company that PG is better than MySQL.
>
>These may be helpful:
>
>http://wiki.postgresql.org/wiki/Why_PostgreSQL_Instead_of_MySQL_2009>
>http://www.wikivs.com/wiki/MySQL_vs_PostgreSQL>

Thanks!  I've forwarded this.

However, it doesn't address the assertion about the client library and
wire protocol.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Beware of companies that claim to be like a family.  They might not be
lying."  --Jill Lundquist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2 Debug build

2011-03-17 Thread Santoso Wijaya
Looks like something tripped over whitespaces in path names for svn tools.
Try checking out a working copy from the hg repository?

~/santa


On Thu, Mar 17, 2011 at 3:54 PM, Willis Cheung  wrote:

> Hi all,
>
> I'm trying to build the debug version of Python 3.2. I downloaded the py3k
> folder from the python SVN. Then I opened the pcbuild.sln and tried to build
> the "python" project. However the build failed when I got an error from the
> project "pythoncore" which I think "python" depends on? The error is:
>
> Cannot open source file: 'C:\Program
> Files\py3k\PCbuild\Win32-temp-Debug\pythoncore\\getbuildinfo2.c': No such
> file or directory.
>
>
>
> The log also mentioned the following couple lines before:
>
>
>
> 5>"C:\Program Files\TortoiseSVN\bin\subwcrev.exe" ..
> ..\Modules\getbuildinfo.c "C:\Program
> Files\py3k\PCbuild\Win32-temp-Debug\pythoncore\\getbuildinfo2.c"
> 5>'C:\Program' is not recognized as an internal or external command,
>
>
> I did get the debug build of python 2.7.1 and 3.1.3 to work successfully so
> I'm not quite sure if I'm supposed to do anything different for Python 3.2.
> Can anyone guide me on this? Thank you.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fitting polynomial curve

2011-03-17 Thread Astan Chee
On Thu, Mar 17, 2011 at 5:09 PM, Terry Reedy  wrote:

> Look at scipy.
>
> --
>

Thanks for the info. I realized I made some mistakes. Anyway, what I'm
trying to do is in maya (python), fit selected vertices on a curve. Here is
what I have so far:

import maya.cmds as cmds
import numpy

def run_main():
verts = cmds.ls(sl=True,fl=True)
if len(verts) >= 2:
degree = 5
x = []
y = []
for vert in verts:
vert_x,vert_y,vert_z = cmds.pointPosition(vert,w=True)
x.append(vert_x)
y.append(vert_z)
print "x ", x
print "y ", y
x_numpy = numpy.array(x)
y_numpy = numpy.array(y)
funct = numpy.polyfit(x_numpy,y_numpy,degree)
print funct #p : ndarray, shape (M,) or (M, K)
#Polynomial coefficients, highest power first. If y was 2-D,
the coefficients for k-th data set are in p[:,k].
#make an outline curve
curvs = []
for i in range(len(verts)):
vert_x,vert_y,vert_z = cmds.pointPosition(verts[i],w=True)
pos_x = 0
pos_y = 0
for j in range(degree):
pos_x += (funct[j] *(vert_x**(degree-j)))
pos_y += (funct[j] *(vert_y**(degree-j)))
centerPos = (pos_x,pos_y,vert_z)
curvs.append(centerPos)
if curvs:
print "cirv ", curvs
crv = cmds.curve(p=curvs)
cmds.select(cl=True)
for v in verts:
cmds.select(v,tgl=True)

else:
print "please select more than 2 verts"

But this only works for 2D (x,z-axis). Is it possible to make it work at 3
by combining them or doing (x,y) and (x,z) and somehow colate (average?) the
results? Is there a formula for combining the results?
Thanks again for any help or suggestions
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to use variable to substitute class's variable?

2011-03-17 Thread Hans
On Mar 17, 12:47 am, Benjamin Kaplan  wrote:
> On Thu, Mar 17, 2011 at 3:31 AM, Hans  wrote:
> > I have things like:
> > file1:
> > class aaa:
> >    def __init__(self):
> >        self.variable1='a1'
> >        self.variable2='a2'
> >        self.varable3='a3'
>
> > in main proc:
> > import file1
> > b=file1.aaa()
> > c={'variable1':'value1','variable2':'value2','variable3':'value3'}
> > for key in c:
> >    b.key=c[key]  >>>Problem is here!!!
>
> > I hope put value1 to b.variable1, value2 to b.variable2 and value3 to
> > b.variable3. it does not work.  How can I do it?
>
> b.key gets the "key" attribute of b, not the attribute that has the
> same name as the variable called key. Otherwise, you'd have to
> reference it as b."key" normally. If you want to dynamically set the
> variable, you'll have to use the setattr function
>
> setattr(b, key, c[key])
>
>
>
> > By the way, I know dictionary can bind two variable together, like a 2-
> > dimension array.  but, if I need group 3 or more variables together,
> > (each group has 3 or more variables)like a 3-dimension(or higher)
> > array, Is there an easy way besides "class"?
>
> A dictionary does not bind two variables together. A dictionary is a
> hash map- it maps keys to values. Each key will map to exactly one
> value. If you want to store a list of associated values, use a tuple.
> A tuple is an immutable collection of objects (the tuple itself is
> immutable, not necessarily the objects in it). It can be indexed just
> like a list.
>
>
>
> >>> l = [(0,0), (0,1,2,3,4,5,6,7), (0,1,'foo', 5 ,6)]
> >>> l[0]
> (0, 0)
> >>> l[2]
> (0, 1, 'foo', 5, 6)
> >>> l[2][1]- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Thank you VERY MUCH! it works.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: enhanced map function

2011-03-17 Thread Steven D'Aprano
On Thu, 17 Mar 2011 08:31:28 -0700, Patrick wrote:

> Steven,
> 
> Thanks for the info of itertools. It is a great start for me. Overall, I
> agree with you that it is really the user data needs to be sorted out.
> However, novice users may need help on certain patterns such as
> "a=[1,[2,3],4], b=[5,[6,7,8],9,10]". 


You have misunderstood me. I'm not saying that you should force the users 
to clean up the data (although of course you could do that), but that you 
should do so before handing it to map.

Rather than putting all the smarts into enhanced_map, and having it 
understand what to do with mismatched nested lists, deep nesting, 
integers where you would expect a list, etc., you should write another 
function that takes the user's data and adjusts it to some known, 
consistent format, and then pass that on to map. Don't have one function 
try to do too much.



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


Abend with cls.__repr__ = cls.__str__ on Windows.

2011-03-17 Thread J Peyret
This gives a particularly nasty abend in Windows - "Python.exe has
stopped working", rather than a regular exception stack error.  I've
fixed it, after I figured out the cause, which took a while, but maybe
someone will benefit from this.

Python 2.6.5 on Windows 7.



class Foo(object):
pass

#def __str__(self):  #if you have this defined, no abend
#return "a Foo"

Foo.__repr__ = Foo.__str__   # this will cause an abend.

#Foo.__str__ = Foo.__repr__  #do this instead, no abend

foo = Foo()

print str(foo)



I suspect that object.__str__ is really object.__repr__ by default, as
they both print out the same string, so that this doesn't make any
sense.

What was I trying to achieve?  Leveraging __str__ to debug instances
in lists and containers.  In that case, __repr__ is called and I
usually do:

class Foo(object):
  def __str__(self):
 return "a foo"
  def __repr__(self):  #was trying to avoid this.
 return str(self)
-- 
http://mail.python.org/mailman/listinfo/python-list


Announce: WHIFF 1.1 Release

2011-03-17 Thread Aaron Watters
WHIFF 1.1 RELEASED

WHIFF [WSGI HTTP Integrated Filesystem Frames]
is a collection of support services
for Python/WSGI Web applications which
allows applications to be composed by
"dropping" dynamic pages into container
directories.

This mode of development will be familiar
to developers who have created PHP
applications, vanilla CGI scripts,
Apache/modpy Publisher applications,
JSP pages, or static web content.

WHIFF 1.1 improves support for Google App
Engine applications and fixes a number of
bugs/misfeatures regarding string quoting
and encoding.

PROJECT PAGE: http://whiff.sourceforge.net/
DOCUMENTATION: http://whiffdoc.appspot.com
DOWNLOAD: https://sourceforge.net/projects/whiff/
REPOSITORY: http://code.google.com/p/whiff/source/checkout

Please read about the features, tutorials, and demos:

Test drive
  http://whiffdoc.appspot.com/docs/W1100_0500.TestDrive
Mako template support
  http://whiffdoc.appspot.com/docs/W1100_1075.MakoGrading
Drop down menus middlewares
  http://whiffdoc.appspot.com/docs/W1100_1300.menus
AJAX callback support
  http://whiffdoc.appspot.com/docs/W1100_1400.calc
Jquery helpers
  http://whiffdoc.appspot.com/docs/W1100_1450.jQueryUI
Integration support for repoze.who authentication
  http://whiffdoc.appspot.com/docs/W1100_1500.who
Open Flash Charts
  http://whiffdoc.appspot.com/docs/W1100_1600.openFlashCharts
Internationalization support
  http://whiffdoc.appspot.com/docs/W1100_1700.international
Tree views with AJAX callbacks
  http://whiffdoc.appspot.com/docs/W1100_2200.TreeView
Google App Engine compatibility
  http://whiffdoc.appspot.com/docs/W1100_2300.GAEDeploy

And much more.

Please try it out and let me know what you
think.  Also, thanks to all for suggestions and other
feedback.

-- Aaron Watters

===
This one goes to eleven.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ttk styles

2011-03-17 Thread Ned Deily
In article 
,
 Peter  wrote:

> No responses? Nobody with knowledge of modifying styles etc?

You might also want to ask on the tkinter mailing list:

http://mail.python.org/pipermail/tkinter-discuss/

-- 
 Ned Deily,
 n...@acm.org

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


Re: Coding and Decoding in Python

2011-03-17 Thread Steven D'Aprano
On Thu, 17 Mar 2011 08:07:28 -0700, Wanderer wrote:

> I have a dll that to communicate with I need to send numeric codes. So I
> created a dictionary. It works in one direction in that I can address
> the key and get the value. But when the program returns the value I
> can't get the key.

If you only have a few keys:

def find_key(value, d):
"""Return the key in dictionary d that has the given value.
If there are multiple keys with the same value, return an
arbitrarily chosen one."""
for k, v in d.items():
if v == value: return k
raise KeyError('no such value found')


If you have many keys/values, then simply create a reverse dictionary:

Rev_QCam_Info = {}
for key, value in QCam_Info.items():
Rev_QCam_Info[value] = key

and then search that.




-- 
Steven

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


Re: Python 3.2 Debug build

2011-03-17 Thread Terry Reedy

On 3/17/2011 6:54 PM, Willis Cheung wrote:

Hi all,

I'm trying to build the debug version of Python 3.2. I downloaded the
py3k folder from the python SVN.


Just so you know, Python SVN is now a read-only historical arifact. 
Development now happens in the hg repository. If you build x.y docs, you 
might as well get the latest even you want to build from a frozen x.y.z 
code branch.


Unfortunately, I have no idea about your specific problem. I presume 
someone has done a 3.2 debug build on windows, but do not know for sure.


--
Terry Jan Reedy

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


Python 3.2 Debug build

2011-03-17 Thread Willis Cheung
Hi all,

I'm trying to build the debug version of Python 3.2. I downloaded the py3k
folder from the python SVN. Then I opened the pcbuild.sln and tried to build
the "python" project. However the build failed when I got an error from the
project "pythoncore" which I think "python" depends on? The error is:

Cannot open source file: 'C:\Program
Files\py3k\PCbuild\Win32-temp-Debug\pythoncore\\getbuildinfo2.c': No such
file or directory.



The log also mentioned the following couple lines before:

 

5>"C:\Program Files\TortoiseSVN\bin\subwcrev.exe" ..
..\Modules\getbuildinfo.c "C:\Program
Files\py3k\PCbuild\Win32-temp-Debug\pythoncore\\getbuildinfo2.c"
5>'C:\Program' is not recognized as an internal or external command,


I did get the debug build of python 2.7.1 and 3.1.3 to work successfully so
I'm not quite sure if I'm supposed to do anything different for Python 3.2.
Can anyone guide me on this? Thank you.

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


Re: ttk styles

2011-03-17 Thread Ethan Furman

Peter wrote:

Thanks for the link Malcolm, I'll have a look at it. What is
particularly interesting (at first glance), is that the author has
"mixed" Tkinter with ttk as it suited i.e. look at this line:

f1 = tkinter.Frame(nb, background="red")

If ttk was being used purely (from tkinter import *; from ttk import
*) then the "background" keyword is nolonger available/recognised and
the code would have to use ttk styles to change the colour - I find it
somewhat disappointing that the author felt this approach was
necessary as it tends to dilute the example by not keeping everything
purely ttk - modifying the style to change the background of the Frame
statements would have made it an even better example!

I will repost the answer if I can work it out using this example code
- thanks again! :-)


Another place to look for inspiration is http://tkdocs.com/

One thing to keep in mind is that not all widgets in tkinter have been 
migrated to ttk (although Frame was).


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


Re: ttk styles

2011-03-17 Thread Peter
Thanks for the link Malcolm, I'll have a look at it. What is
particularly interesting (at first glance), is that the author has
"mixed" Tkinter with ttk as it suited i.e. look at this line:

f1 = tkinter.Frame(nb, background="red")

If ttk was being used purely (from tkinter import *; from ttk import
*) then the "background" keyword is nolonger available/recognised and
the code would have to use ttk styles to change the colour - I find it
somewhat disappointing that the author felt this approach was
necessary as it tends to dilute the example by not keeping everything
purely ttk - modifying the style to change the background of the Frame
statements would have made it an even better example!

I will repost the answer if I can work it out using this example code
- thanks again! :-)

Peter

On Mar 18, 9:14 am, pyt...@bdurham.com wrote:
> Peter,
>
> Sorry I can't be of much help, but I share the same interest as you.
>
> There may be some teaser info here although I can't claim to understand
> the 
> technique.http://www.java2s.com/Open-Source/Python/3.1.2-Python/Demo/Demo/tkint...
>
> If you have any links/documentation to share, I would love to see what
> you've found so far.
>
> Malcolm

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


Re: reimport module every n seconds

2011-03-17 Thread Aahz
In article <753e9884-60eb-43cf-a647-12b29ed28...@y31g2000prd.googlegroups.com>,
Santiago Caracol   wrote:
>>> Don't do that. =A0;-) =A0I suggest using exec instead. =A0However, I wo=
>uld be
>>> surprised if import worked faster than, say, JSON (more precisely, I
>>> doubt that it's enough faster to warrnat this kludge).
>>
>> I'm with Aahz. =A0Don't do that.
>>
>> I don't know what you're doing, but I suspect an even better solution
>> would be to have your program run a "reconfigure" thread which listens
>> on a UDP socket and reads a JSON object from it. =A0Or, at the very least=
>,
>> which listens for a signal which kicks it to re-read some JSON from a
>> disk file. =A0This will be more responsive when the data changes quickly
>> and more efficient when it changes slowly. =A0As opposed to just polling
>> for changes every 10 seconds.
>
>Somehow I guessed that I would be told not to do it. But it's my
>fault. I should have been more explicit. The data is not just data. It
>is a large set of Django objects I call "ContentClassifiers" that have
>each certain methods that calculate from user input very large regular
>expressions. They they have a method "classify" that is applied to
>messages and uses the very large regular expressions. To classify a
>message I simply apply the classify method of all ContentClassifiers.
>There are very many Contentclassifiers.  I compile the
>ContentClassifiers, which are Django objects, to pure Python objects
>in order to not have to fetch them from the database each time I need
>them and in order to be able to compile the large regular expressions
>offline. In Django, I generated and compiled each regular expressions
>of each ContentClassifier each time I needed it to classify a message.
>I didn't find a good way to calculate and compile the regular
>expressions once and store them.
>
>I already tested the automatically generated module: Before,
>classifying a message took about 10 seconds, now it takes miliseconds.
>
>My only problem is reloading the module: At the time being, I simply
>restart the web server manually from time to time in order to load the
>freshly compiled module.

Why not just create a second process and send the messages there?  Then
restart the second process each time you need to reload.  That can be
easily automated.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Beware of companies that claim to be like a family.  They might not be
lying."  --Jill Lundquist
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ttk styles

2011-03-17 Thread python
Peter,

Sorry I can't be of much help, but I share the same interest as you.

There may be some teaser info here although I can't claim to understand
the technique.
http://www.java2s.com/Open-Source/Python/3.1.2-Python/Demo/Demo/tkinter/ttk/notebook_closebtn.py.htm

If you have any links/documentation to share, I would love to see what
you've found so far.

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


Re: ttk styles

2011-03-17 Thread Peter
No responses? Nobody with knowledge of modifying styles etc?

On Mar 14, 2:08 pm, Peter  wrote:
> Hi I'm struggling to get a good understanding of styles as used in
> ttk. I have read the tutorial section on using styles but haven't been
> able to solve this problem.
>
> I am attempting to create a Checkbutton with the indicatoron=false
> option. Using ttk the documentation is clear that you have to create a
> custom style to achieve this behaviour. But the only "example" I have
> been able to find on the Internet searches is written in Tcl i.e. here
> is what I have found (quoted directly):
>
> Here’s how you set it up: To achieve the effect of -indicatoron false,
> create a new layout that doesn’t have an indicator:
>
> style layout Toolbar.TCheckbutton {
>       Toolbutton.border -children {
>            Toolbutton.padding -children {
>                  Toolbutton.label
>            }
>       }
>
> }
>
> Then use style map and style default to control the border appearance:
>
> style default Toolbar.TCheckbutton \
>      -relief flat
> style map Toolbar.TCheckbutton -relief {
>       disabled flat
>       selected sunken
>       pressed sunken
>       active raised
>
> Hopefully somebody else in this group has "done" this and can post
> their "solution"?
>
> Thanks
> Peter

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


Re: value of pi and 22/7

2011-03-17 Thread Jabba Laci
> My favorite approximation is: 355/113  (visualize 113355 split into two 113 
> 355 and then do the division). The first 6 decimal places are the same.
>
> 3.141592920353982 = 355/113
> vs
> 3.1415926535897931

Another, rather funny, approximation of the first 15 digits of pi is
to take the length of the words in the following verse:

s = """
How I want a drink
alcoholic of course
After the heavy lectures
involving complex functions
"""

print [len(w) for w in s.split()]

will produce:

[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9]

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


Re: value of pi and 22/7

2011-03-17 Thread Erik Max Francis

Jeffrey Gaynor wrote:
It is the simple "fractional" look about pi vs. how hard it is to compute that drives most 
of the confusion about pi. The digits of pi are in effectively random order (each digit occur 
roughly 10% of the time), ...


This is equivalent to stating that pi is normal, something which is 
widely suspected but has not yet been proven.


There are fun math questions, for instance, is there a run of a million 1's someplace in the 
decimal expansion of pi?


The answer is yes, if pi is normal.  Every finite sequence of digits 
will appear with the expected frequency.  In all bases.


--
Erik Max Francis && m...@alcyone.com && http://www.alcyone.com/max/
 San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis
  They love too much that die for love.
   -- (an English proverb)
--
http://mail.python.org/mailman/listinfo/python-list


Re: value of pi and 22/7

2011-03-17 Thread Rotwang

On 17/03/2011 18:49, Ian Kelly wrote:

On Thu, Mar 17, 2011 at 11:36 AM, Jeffrey Gaynor  wrote:

There are fun math questions, for instance, is there a run of a million 1's 
someplace in the decimal expansion of pi? Maybe so, but we just don't know, 
since we've only computed the first trillion or so digits.


Since pi is irrational I would be surprised if there isn't one
eventually.  Out of my own curiosity, do you know what the longest
known string of repeating digits in pi is?


Note that Liouville's constant, the number sum_{j = 1}^\infty 10^{-j!} 
is easily seen to be irrational (and is also transcendental), but no 
string of a million 1's, or any digit other than 0 and 1, appears in its 
decimal expansion. The relevant concept is that of a normal number, 
which is one whose digits "look random":


http://en.wikipedia.org/wiki/Normal_number

Pi has not been proved to be normal but it is suspected on purely 
statistical grounds that it is, since almost all real numbers are normal 
(in the sense that the set of non-normal real numbers has Lebesgue 
measure 0).

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


Re: value of pi and 22/7

2011-03-17 Thread Jeffrey Gaynor
There are a few long strings, but have fun yourself with the pi digit searcher:

http://www.angio.net/pi/bigpi.cgi

Longest string I heard of was nine 6's in a row, so search for 6 and 
see what you get.

- Original Message -
From: "Ian Kelly" 
To: "Jeffrey Gaynor" 
Cc: python-list@python.org
Sent: Thursday, March 17, 2011 1:49:56 PM
Subject: Re: value of pi and 22/7

On Thu, Mar 17, 2011 at 11:36 AM, Jeffrey Gaynor  wrote:
> There are fun math questions, for instance, is there a run of a million 1's 
> someplace in the decimal expansion of pi? Maybe so, but we just don't know, 
> since we've only computed the first trillion or so digits.

Since pi is irrational I would be surprised if there isn't one
eventually.  Out of my own curiosity, do you know what the longest
known string of repeating digits in pi is?

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


Re: value of pi and 22/7

2011-03-17 Thread Ian Kelly
On Thu, Mar 17, 2011 at 11:36 AM, Jeffrey Gaynor  wrote:
> There are fun math questions, for instance, is there a run of a million 1's 
> someplace in the decimal expansion of pi? Maybe so, but we just don't know, 
> since we've only computed the first trillion or so digits.

Since pi is irrational I would be surprised if there isn't one
eventually.  Out of my own curiosity, do you know what the longest
known string of repeating digits in pi is?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: value of pi and 22/7

2011-03-17 Thread Jeffrey Gaynor
(pulls out doctorate in Math.) Take a circle and measure its diameter, then 
circumference (coffee cans and string are helpful). Then

pi = Circumference/diameter

approximating that is hard. It turns out that even though it *looks* like a 
nice fraction, the value that results is not (fractions of integers have the 
charming property that they always repeat, for instance 22/7 = 3.142857 142857 
142857 142857 142857... Pi does not. Again this was a very hard question only 
answered in the 18th century by Lambert, I do believe.)

It is the simple "fractional" look about pi vs. how hard it is to compute that 
drives most of the confusion about pi. The digits of pi are in effectively 
random order (each digit occur roughly 10% of the time), and to compute the nth 
one you need all the digits before it. Once upon a time (and maybe still) 
sending back and forth long strings of the digits of pi was a great way to test 
communications, since each side could look up the result in a table and tell if 
there were systematic errors. There are fun math questions, for instance, is 
there a run of a million 1's someplace in the decimal expansion of pi? Maybe 
so, but we just don't know, since we've only computed the first trillion or so 
digits. Computing pi also requires a lot of logistical organization too and 
cranking out the first several hundred million digits is still often used to 
test systems. 

FWIW my favorite approximation is 355/113. I can always seem to remember that 
one the best...

Jeff

- Original Message -
From: "kracekumar ramaraju" 
To: python-list@python.org
Sent: Thursday, March 17, 2011 11:46:25 AM
Subject: value of pi and 22/7


I tried the following 
>>> 22/7.0 
3.1428571428571428 
>>> import math 
>>> math.pi 
3.1415926535897931 
>>> 


Why is the difference is so much ?is pi =22/7 or something ? 
-- 
winning regards 
kracekumar 

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


Re: PEP for module naming conventions

2011-03-17 Thread Jonathan Gossage
I have found this approach problematic if you have packages separately
developed and maintained in different directory trees, resulting in
more than one PYTHONPATH entry with the same root metapackage name.
What happens is that only the first entry in the PYTHONPATH containing
the metapackage name is looked in for package/module resolution. Do
you have any suggestions for handling this kind of packaging?


On Thu, Mar 17, 2011 at 12:17 PM, eryksun ()  wrote:
> On Friday, March 11, 2011 4:52:57 PM UTC-5, Tim Johnson wrote:
>> I need to be better informed on naming conventions for modules.  For
>> instance, I need to create a new module and I want to make sure that
>> the module name will not conflict with any future or current python
>> system module names.
>
> Do you mean package names? Within a package you can use relative imports to 
> avoid conflicts. You could put all of your packages in a metapackage 
> namespace with a unique name -- a company/group name or personal/family name, 
> an uncommon English word, or something from another language.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: value of pi and 22/7

2011-03-17 Thread Kee Nethery
My favorite approximation is: 355/113  (visualize 113355 split into two 113 355 
and then do the division). The first 6 decimal places are the same.

3.141592920353982 = 355/113
vs
3.1415926535897931 

Kee Nethery



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


Re: PDF To Postscript

2011-03-17 Thread Adam Tauno Williams
On Thu, 2011-03-17 at 08:53 -0700, Chris Rebert wrote:
> On Thu, Mar 17, 2011 at 6:55 AM, Adam Tauno Williams
>  wrote:
> > PyPDF (and others) provide a very nice mechanism for creating and
> > manipulating PDF documents.  Is there any *Python* module or technique
> > to turn a PDF document into Postscript [to print, for example]?
> Considering your post is currently the top Google hit for " "pdf to
> postscript" python ", this seems unlikely. :-(

True.  I've found the "ghostscript" module which integrates with the GS
application via ctypes.  It 'works' but currently there is an issue with
redirected stdin/stdout [processing streams].



> From what I can gather, it seems using the pdftops program from xpdf
> or poppler (or the lesser, distinct pdf2ps program) is the way people
> go about handling this.

Yep, which is a sad and fragile hack.


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


Re: value of pi and 22/7

2011-03-17 Thread Ian Kelly
On Thu, Mar 17, 2011 at 10:57 AM, Ian Kelly  wrote:
> On Thu, Mar 17, 2011 at 10:46 AM, kracekumar ramaraju
>  wrote:
>> I tried the following
> 22/7.0
>> 3.1428571428571428
> import math
> math.pi
>> 3.1415926535897931
>
>>
>>
>> Why is the difference is so much ?is pi =22/7 or something ?
>
> Pi is not 22/7.  That is just a commonly-used approximation.

I should add that math.pi is also not pi, because pi cannot be exactly
represented as a floating-point number.  It is another approximation
that has several more digits of precision than 22/7.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: value of pi and 22/7

2011-03-17 Thread Ian Kelly
On Thu, Mar 17, 2011 at 10:46 AM, kracekumar ramaraju
 wrote:
> I tried the following
 22/7.0
> 3.1428571428571428
 import math
 math.pi
> 3.1415926535897931

>
>
> Why is the difference is so much ?is pi =22/7 or something ?

Pi is not 22/7.  That is just a commonly-used approximation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: value of pi and 22/7

2011-03-17 Thread Wolfgang Rohdewald
On Donnerstag 17 März 2011, kracekumar ramaraju wrote:

> >>> 22/7.0
> 
> 3.1428571428571428
> 
> >>> import math
> >>> math.pi
> 
> 3.1415926535897931
> 
> Why is the difference is so much ?is pi =22/7 or something ?

https://secure.wikimedia.org/wikipedia/en/wiki/Pi

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


value of pi and 22/7

2011-03-17 Thread kracekumar ramaraju
I tried the following
>>> 22/7.0
3.1428571428571428
>>> import math
>>> math.pi
3.1415926535897931
>>>


Why is the difference is so much ?is pi =22/7 or something ?
-- 
winning regards
kracekumar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP for module naming conventions

2011-03-17 Thread eryksun ()
On Friday, March 11, 2011 4:52:57 PM UTC-5, Tim Johnson wrote:
> I need to be better informed on naming conventions for modules.  For
> instance, I need to create a new module and I want to make sure that
> the module name will not conflict with any future or current python
> system module names.

Do you mean package names? Within a package you can use relative imports to 
avoid conflicts. You could put all of your packages in a metapackage namespace 
with a unique name -- a company/group name or personal/family name, an uncommon 
English word, or something from another language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coding and Decoding in Python

2011-03-17 Thread John Gordon
In <7546e476-d10f-46e5-8b20-5d9b42345...@r6g2000vbo.googlegroups.com> Wanderer 
 writes:

> I guess two keys having the same value is why dictionaries don't
> return keys for values, but this is a code. Each value has a unique
> meaning to both sender and receiver. The text part is for making the
> program understandable and printing understandable error messages.

I see.  You're storing integer equivalents for the labels themselves,
not the actual data associated with the labels.

Then Mel's solution is a good one -- construct a second dict which
has the keys and values swapped.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Coding and Decoding in Python

2011-03-17 Thread Wanderer
On Mar 17, 11:44 am, John Gordon  wrote:
> In <2f4a08df-55ea-4a4e-9cc0-24e6b9f81...@f15g2000pro.googlegroups.com> 
> Wanderer  writes:
>
> > But when the program returns the value I can't get the key.
>
> What happens when two keys have the same value?  How would you know which
> key to return?
>
> In your sample code all the values are different, but surely that won't
> always be the case with real data.
>
> --
> John Gordon                   A is for Amy, who fell down the stairs
> gor...@panix.com              B is for Basil, assaulted by bears
>                                 -- Edward Gorey, "The Gashlycrumb Tinies"

I guess two keys having the same value is why dictionaries don't
return keys for values, but this is a code. Each value has a unique
meaning to both sender and receiver. The text part is for making the
program understandable and printing understandable error messages.

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


Re: PDF To Postscript

2011-03-17 Thread Chris Rebert
On Thu, Mar 17, 2011 at 6:55 AM, Adam Tauno Williams
 wrote:
> PyPDF (and others) provide a very nice mechanism for creating and
> manipulating PDF documents.  Is there any *Python* module or technique
> to turn a PDF document into Postscript [to print, for example]?

Considering your post is currently the top Google hit for " "pdf to
postscript" python ", this seems unlikely. :-(
From what I can gather, it seems using the pdftops program from xpdf
or poppler (or the lesser, distinct pdf2ps program) is the way people
go about handling this.
Ghostscript is also apparently a possibility.

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


Re: Coding and Decoding in Python

2011-03-17 Thread John Gordon
In <2f4a08df-55ea-4a4e-9cc0-24e6b9f81...@f15g2000pro.googlegroups.com> Wanderer 
 writes:

> But when the program returns the value I can't get the key.

What happens when two keys have the same value?  How would you know which
key to return?

In your sample code all the values are different, but surely that won't
always be the case with real data.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: enhanced map function

2011-03-17 Thread Patrick
Steven,

Thanks for the info of itertools. It is a great start for me. Overall,
I agree with you that it is really the user data needs to be sorted
out. However, novice users may need help on certain patterns such as
"a=[1,[2,3],4], b=[5,[6,7,8],9,10]". We could just draw our line
saying that similarly nested inputs could be adjusted even though the
members aren't exactly on one-to-one mapping and we won't getting any
deeper for complicated cases such as "a = [1, 2, [3, 4]]; b = [1, [2,
[3,4]], [4,5], 6]".

> enhanced_map([1, [2,3, [4,5], 6], 7], [8, [7,6, [5,4], 3], 2])
> should be the same as
> map([1, 2, 3, 4, 5, 6, 7], [8, 7, 6, 5, 4, 3, 2])

I don't expect the drop. The original nested structure is very
important.


> What do you expect to happen if the sub-sequences don't match up exactly?
> E.g. a = [1, 2, [3, 4]]; b = [1, [2, 3], 4]
>
> What do you expect to happen if the shorter list is empty?
> E.g. a = [1, 2, [3, 4], 5]; b = [1, 2, [], 3]

There are modes called "shortest" and "longest" (and
"AllCombination"/"Cross" which is more complex).

For case  a = [1, 2, [3, 4],4]; b = [1, [2, 3], 4,5]

shortest:
   a will be adjusted to [1, [3, 4],4]
   b will be adjusted to [1, [2, 3],4]

longest:
   a will be adjusted to [1, 2,[3, 4],4,4]
   b will be adjusted to [1, 1,[2, 3],4,5]

As I said previously, the enhance_map function will only handle
limited "unmatch" cases and the line will need to be drawn carefully.

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


Re: PEP for module naming conventions

2011-03-17 Thread Mel
Tim Johnson wrote:

> I need to be better informed on naming conventions for modules.  For
> instance, I need to create a new module and I want to make sure that
> the module name will not conflict with any future or current python
> system module names.

COBOL in its golden years had a practice that reserved words were almost 
never hyphenated -- the few that were could be counted on the fingers of 
perhaps four hands and were mostly required paragraph names that were always 
used and hard to forget.

It might turn out well to specify that system module names will never 
contain more than, say, one underscore.  That way, nice descriptive 
application module names like 'analyzer_tool_utils' and such would always be 
safe to use.

Mel.

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


Re: Coding and Decoding in Python

2011-03-17 Thread Mel
Wanderer wrote:

> I have a dll that to communicate with I need to send numeric codes. So
> I created a dictionary. It works in one direction in that I can
> address the key and get the value. But when the program returns the
> value I can't get the key. This code is very simple and I could use a
> list and the index except for the last value. Is there a better way to
> handle coding and decoding values to strings?
> 
> QCam_Info = {
> 'qinfCameraType' : 0,# Camera model (see
> QCam_qcCameraType)
> 'qinfSerialNumber': 1,# Deprecated
> 'qinfHardwareVersion'   : 2,# Hardware version
> 'qinfFirmwareVersion'   : 3,# Firmware version
> 'qinfCcd'  : 4,# CCD model (see
> QCam_qcCcd)
[ ... ]
 '_qinf_force32'   : 0x
> }

I handled this problem in a kind of cheap, nasty way with (untested)

for k, v in QCam_Info.items():
QCam_Info[v] = k

Then the dictionary lookups work both ways.

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


Coding and Decoding in Python

2011-03-17 Thread Wanderer
I have a dll that to communicate with I need to send numeric codes. So
I created a dictionary. It works in one direction in that I can
address the key and get the value. But when the program returns the
value I can't get the key. This code is very simple and I could use a
list and the index except for the last value. Is there a better way to
handle coding and decoding values to strings?

QCam_Info = {
'qinfCameraType' : 0,# Camera model (see
QCam_qcCameraType)
'qinfSerialNumber': 1,# Deprecated
'qinfHardwareVersion'   : 2,# Hardware version
'qinfFirmwareVersion'   : 3,# Firmware version
'qinfCcd'  : 4,# CCD model (see
QCam_qcCcd)
'qinfBitDepth'   : 5,# Maximum bit depth
'qinfCooled'  : 6,# Returns 1 if
cooler is available, 0 if not
'qinfReserved1' : 7,# Reserved
'qinfImageWidth '  : 8,# Width of the ROI (in
pixels)
'qinfImageHeight'  : 9,# Height of the ROI (in
pixels)
'qinfImageSize' : 10,   # Size of returned
image (in bytes)
'qinfCcdType'   : 11,   # CDD type (see
QCam_qcCcdType)
'qinfCcdWidth'  : 12,   # CCD maximum width
'qinfCcdHeight' : 13,   # CCD maximum height
'qinfFirmwareBuild': 14,   # Build number of the
firmware
'qinfUniqueId': 15,   # Same as uniqueId
in QCam_CamListItem
'qinfIsModelB'   : 16,   # Cameras
manufactured after March 1, 2004 return 1, otherwise 0
'qinfIntensifierModel'  : 17,   # Intensifier tube
model (see QCam_qcIntensifierModel)
'qinfExposureRes' : 18,   # Exposure time
resolution (nanoseconds)
'qinfTriggerDelayRes' : 19,   # Trigger delay
Resolution (nanoseconds)
'qinfStreamVersion'   : 20,   # Streaming version
'qinfNormGainSigFigs'   : 21,   # Normalized Gain
Significant Figures resolution
'qinfNormGaindBRes': 22,   # Normalized Gain dB
resolution (in micro units)
'qinfNormITGainSigFigs': 23,   # Normalized Intensifier
Gain Significant Figures
'qinfNormITGaindBRes' : 24,   # Normalized Intensifier
Gain dB resolution (micro units)
'qinfRegulatedCooling'   : 25,   # 1 if camera has
regulated cooling
'qinfRegulatedCoolingLock': 26,   # 1 if camera is at
regulated temperature, 0 otherwise
'qinfFanControl'  : 29,   # 1 if camera can
control fan speed
'qinfHighSensitivityMode' : 30,   # 1 if camera has high
sensitivity mode available
'qinfBlackoutMode': 31,   # 1 if camera has
blackout mode available
'qinfPostProcessImageSize': 32,   # Returns the size (in
bytes) of the post-processed image
'qinfAsymmetricalBinning' : 33,   # 1 if camera has
asymmetrical binning (ex: 2x4)
'qinfEMGain'  : 34,   # 1 if EM gain is
supported, 0 if not
'qinfOpenDelay'   : 35,   # 1 if shutter open
delay controls are available, 0 if not
'qinfCloseDelay'  : 36,   # 1 if shutter close
delay controls are available, 0 if not
'qinfColorWheelSupported' : 37,   # 1 if color wheel is
supported, 0 if not
'qinfReserved2'   : 38,
'qinfReserved3'   : 39,
'qinfReserved4'   : 40,
'qinfReserved5'   : 41,
'qinfEasyEmModeSupported' : 42,   # 1 if camera supports
Easy EM mode
'qinfLockedGainModeSupported' : 43,
'qinf_last'   : 44,
'_qinf_force32'   : 0x
}
-- 
http://mail.python.org/mailman/listinfo/python-list


PDF To Postscript

2011-03-17 Thread Adam Tauno Williams
PyPDF (and others) provide a very nice mechanism for creating and
manipulating PDF documents.  Is there any *Python* module or technique
to turn a PDF document into Postscript [to print, for example]?

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


Re: organizing many python scripts, in a large corporate environment.

2011-03-17 Thread eryksun ()
On Wednesday, March 16, 2011 9:03:19 PM UTC-4, bukzor wrote:
>
> I finally understand. You mean something along the lines of `kde-
> config`: an executable to help figure out the configuration at
> runtime. This requires either installation or control of the $PATH
> environment variable to work well, which makes not so useful to me.

There's always the virtualenv option in a POSIX system. Just change the shebang 
to point to your package's virtual Python installation. That obviously won't 
work for Windows, which uses system-wide file-type associations. I think the 
closest to shebang-style control on Windows would require changing the file 
extension to something like 'py_' and having an admin add the appropriate 
ftype/assoc to the system, the same as is done for the pyw extension. That 
would be obscene.

If the problem with installation is merely continuing to have central access to 
the scripts for development, you could deploy with setuptools in development 
mode:

http://packages.python.org/distribute/setuptools.html#development-mode
http://packages.python.org/distribute/setuptools.html#develop

However, I think over time you may come to regret this as other group's 
projects become dependent on your code's behavior (including bugs) and a rigid 
interface.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.walk() to get full path of all files

2011-03-17 Thread Jussi Piitulainen
Laurent Claessens writes:

> > file_list = []
> > for root, _, filenames in os.walk(root_path):
> >   for filename in filenames:
> >   file_list.append(os.path.join(root, filename))
> 
> What does the notation "_" stands for ? Is it a sort of /dev/null ?

   >>> x, _, y = 1, "hukairs", 3
   >>> x, y
   (1, 3)
   >>> _
   'hukairs'
   >>> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.walk() to get full path of all files

2011-03-17 Thread Tim Golden

On 17/03/2011 08:58, Laurent Claessens wrote:



file_list = []
for root, _, filenames in os.walk(root_path):
for filename in filenames:
file_list.append(os.path.join(root, filename))



What does the notation "_" stands for ? Is it a sort of /dev/null ?

I know that in the terminal it represents the last printed text.


It's a convention for saying "I don't really care about this
particular value which is returned from that function". You
could, at your whim, use "dontcare" or "x" or whatever.

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


Re: os.path.walk() to get full path of all files

2011-03-17 Thread Laurent Claessens



file_list = []
for root, _, filenames in os.walk(root_path):
  for filename in filenames:
  file_list.append(os.path.join(root, filename))



What does the notation "_" stands for ? Is it a sort of /dev/null ?

I know that in the terminal it represents the last printed text.

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


newbie question (latex Error in plotting)

2011-03-17 Thread Sachin Kumar Sharma
Hi,

After computation of few array, when I am using plot(x,y) command I get 
following error

'latex' is not recognized as an internal or external command,
operable program or batch file.
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (532, 0))

ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (19, 0))

I can view the output as and it is fine. I tried the same in Ipython and 
spyder, same error message.

Any advice.

Cheers

Sachin


Sachin Kumar Sharma
Senior Geomodeler

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


Re: how to use variable to substitute class's variable?

2011-03-17 Thread Benjamin Kaplan
On Thu, Mar 17, 2011 at 3:31 AM, Hans  wrote:
> I have things like:
> file1:
> class aaa:
>    def __init__(self):
>        self.variable1='a1'
>        self.variable2='a2'
>        self.varable3='a3'
>
>
> in main proc:
> import file1
> b=file1.aaa()
> c={'variable1':'value1','variable2':'value2','variable3':'value3'}
> for key in c:
>    b.key=c[key]  >>>Problem is here!!!
>
> I hope put value1 to b.variable1, value2 to b.variable2 and value3 to
> b.variable3. it does not work.  How can I do it?
>

b.key gets the "key" attribute of b, not the attribute that has the
same name as the variable called key. Otherwise, you'd have to
reference it as b."key" normally. If you want to dynamically set the
variable, you'll have to use the setattr function

setattr(b, key, c[key])

>
> By the way, I know dictionary can bind two variable together, like a 2-
> dimension array.  but, if I need group 3 or more variables together,
> (each group has 3 or more variables)like a 3-dimension(or higher)
> array, Is there an easy way besides "class"?
>

A dictionary does not bind two variables together. A dictionary is a
hash map- it maps keys to values. Each key will map to exactly one
value. If you want to store a list of associated values, use a tuple.
A tuple is an immutable collection of objects (the tuple itself is
immutable, not necessarily the objects in it). It can be indexed just
like a list.
>>> l = [(0,0), (0,1,2,3,4,5,6,7), (0,1,'foo', 5 ,6)]
>>> l[0]
(0, 0)
>>> l[2]
(0, 1, 'foo', 5, 6)
>>> l[2][1]
-- 
http://mail.python.org/mailman/listinfo/python-list


how to use variable to substitute class's variable?

2011-03-17 Thread Hans
I have things like:
file1:
class aaa:
def __init__(self):
self.variable1='a1'
self.variable2='a2'
self.varable3='a3'


in main proc:
import file1
b=file1.aaa()
c={'variable1':'value1','variable2':'value2','variable3':'value3'}
for key in c:
b.key=c[key]  >>>Problem is here!!!

I hope put value1 to b.variable1, value2 to b.variable2 and value3 to
b.variable3. it does not work.  How can I do it?


By the way, I know dictionary can bind two variable together, like a 2-
dimension array.  but, if I need group 3 or more variables together,
(each group has 3 or more variables)like a 3-dimension(or higher)
array, Is there an easy way besides "class"?

Thanks a lot!!!



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