is there a way to get the encoding of python file
hello, Is it possible to get the encoding of a python file from the first source line, (if there's any), after importing it ( with '__import__' ) # -*- coding: windows-1252 -*- thanks, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a library/program that converts sqlite database from windows-1252 to utf-8 ?
On 12-09-2010 00:07, Robert Kern wrote:
> On 9/11/10 4:45 PM, Stef Mientki wrote:
>> On 11-09-2010 21:11, Robert Kern wrote:
>>> SQLite internally stores its strings as UTF-8 or UTF-16 encoded Unicode. So
>>> it's not clear what
>>> you mean when you say the database is "windows-1252". Can you be more
>>> specific?
>> I doubt that, but I'm not sure ...
>
> From the documentation, it looks like SQLite does not attempt to validate the
> input as UTF-8
> encoded, so it is possible that someone pushed in raw bytes. See "Support for
> UTF-8 and UTF-16" in
> the following page:
>
> http://www.sqlite.org/version3.html
>
>> For some databases written by other programs and
>> written with Python, with
>> cursor = self.conn.cursor ()
>> self.conn.text_factory = str
>>
>> Can only be read back with with text_factory = str
>> then the resulting string columns contains normal strings with windows 1252
>> coding, like
>> character 0xC3
>
> You can probably use
>
> self.conn.text_factory = lambda x: x.decode('windows-1252')
>
> to read the data, though I've never tried to use that API myself.
>
> You will need to write a program yourself that opens one connection to your
> existing database for
> reading and another connection to another database (using the defaults) for
> writing. Then iterate
> over your tables and copy data from one database to the other.
>
> You may also be able to simply dump the database to a text file using
> "sqlite3 bad-database.db
> .dump > bad-sql.sql", read the text file into Python as a string, decode it
> from windows-1252 to
> unicode and then encode it as utf-8 and write it back out. Then use "sqlite3
> good-database.db
> .read good-sql.sql" to create the new database. I've never tried such a
> thing, so it may not work.
>
Yes, I think I've to do somethhing like that,
to conserve the structure and field types, it's even more complex.
cheers,
Stef
--
http://mail.python.org/mailman/listinfo/python-list
Re: Queue cleanup
Dennis Lee Bieber wrote: declaimed the following So maybe we need to redesign the hardware. Remember the iAPX-432? http://en.wikipedia.org/wiki/Intel_iAPX_432#Garbage_collection Not quite what I had in mind. That sounds like a conventional GC algorithm that happens to be implemented in microcode. I'm thinking about ways of designing the memory itself to help with GC. Instead of putting all the smarts in the CPU, move some of them into the RAM. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Distribute Non Library
My simple tool writing in python get bigger and bigger and I think I'd better split my code into several files. But, unlike what in some other languages, there is no way to compile these several files into a single executable. Before I splitting my simple tool program, I just put it in /usr/local/bin and run, very simple. Now I have to consider distribute a lot of files in a whole. I know distutils can help, but I feel it is a little uncomfortable, since I am not sharing a library, I am not sharing any thing. I just want to refactory my code. Is there a better solution to my case? Can I simply create a directory in /usr/local/bin and put my script and other used files into the directory? Does distutils help in this case? Thanks in advance. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke -- http://mail.python.org/mailman/listinfo/python-list
click ads of this site for your good, hot and brite future
www.127760.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: The Samurai Principle
On Sun, 12 Sep 2010 12:08:26 +1200, Lawrence D'Oliveiro wrote: >> And that is exactly the reason why the Samurai Principle says to not >> return None when the function fails to do what it intended to do. > > How can the function “fail” when it returns what it is specified to > return? Are you trolling? On the unlikely event that you're not, if you have a function called "len", the *intent* of the function is to return the length of its argument. That's why it's called "len" rather than "raise_exception" or "return_none", say. The use of the term "fail" is entirely unexceptional here. It is normal English to say such things as "the function re.match() returns None if the regular expression fails to match" or "if we fail to acquire a lock, raise an Exception". -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribute Non Library
On Sep 12, 5:10 am, narke wrote: > My simple tool writing in python get bigger and bigger and I think I'd > better split my code into several files. But, unlike what in some other > languages, there is no way to compile these several files into a single > executable. Before I splitting my simple tool program, I just put it in > /usr/local/bin and run, very simple. Now I have to consider distribute > a lot of files in a whole. I know distutils can help, but I feel it is > a little uncomfortable, since I am not sharing a library, I am not > sharing any thing. I just want to refactory my code. Is there a better > solution to my case? Can I simply create a directory in /usr/local/bin > and put my script and other used files into the directory? Does > distutils help in this case? > > Thanks in advance. try : python mayApp.zip myApp.zip <--> all your files + a __main__.py file as a starting point... -- http://mail.python.org/mailman/listinfo/python-list
Minimal-D
Hey I'm creating a program called minimal-d which brings together many "things" you would otherwise use seperate to develop. These things are a file-manager,text-editor,ftp-client and sql-client. The program is currently in alpha, but it would be nice if some people tried it out and pointed out some minors,goodies or things that should/ could be appended. It is written in python 2.6 but 2.4 should be good enough, you also need wxPython 2.8. It is wriiten for linux so if you're on windows use it on your own responsability. you can download a .deb or a .tar.gz from launchpad: http://launchpad.net/d-cm my email: [email protected] further information: http://kruptology.blogspot.com/2010/09/minimal-d-02.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribute Non Library
On Sunday 12 September 2010, it occurred to narke to exclaim: > My simple tool writing in python get bigger and bigger and I think I'd > better split my code into several files. But, unlike what in some other > languages, there is no way to compile these several files into a single > executable. Before I splitting my simple tool program, I just put it in > /usr/local/bin and run, very simple. Now I have to consider distribute > a lot of files in a whole. I know distutils can help, but I feel it is > a little uncomfortable, since I am not sharing a library, I am not > sharing any thing. I just want to refactory my code. Is there a better > solution to my case? Can I simply create a directory in /usr/local/bin > and put my script and other used files into the directory? Does > distutils help in this case? Make it a package (or module), install it with distutils, and create a simple stub script that you put in /usr/local/bin to load it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Static typing, Python, D, DbC
On 09/12/10 08:53, John Nagle wrote: > On 9/11/2010 9:36 AM, Lie Ryan wrote: >> On 09/12/10 00:33, Bearophile wrote: >> >>> >>> >>> Lately while I program with Python one of the D features that I most >>> miss is a built-in Design By Contract (see PEP 316), because it avoids >>> (or helps me to quickly find and fix) many bugs. In my opinion DbC is >>> also very good used with doctests. >> >>> You may implement a poor's man DbC in Python like this: >> >> I would do it like this: > >Design by contract really isn't a good fit to Python. I've > done proof of correctness work, and there are suitable languages > for it. It needs a language where global static analysis is > possible, so you can reliably tell what can changes what. As long as you're not using some funny magic (e.g. monkey patching); then IMO python copes reasonably well. Though, I agree, Python probably isn't really suitable for formal proofing (the best way to assert program's correctness in python is by unittesting, which isn't a formal proof, just one that works most of the time). -- http://mail.python.org/mailman/listinfo/python-list
Re: Static typing, Python, D, DbC
John Nagle: > Design by contract really isn't a good fit to Python. I have used some times the class invariant done manually, as I have shown, and it has avoided me some bugs, so I have experimentally seen you are wrong. > I've done proof of correctness work, and there are suitable languages > for it. It needs a language where global static analysis is > possible, so you can reliably tell what can changes what. I see DbC for Python as a way to avoid or fix some of the bugs of the program, and not to perform proof of correctness of the code. Even if you can't be certain, you are able reduce the probabilities of some bugs to happen. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: play sound on Ubuntu 10.4. (pulse audio?)
Hi Tim,
On 09/11/2010 11:42 PM, Tim Harig wrote:
> On 2010-09-11, News123 wrote:
>> What would be the way to detect how to play audio on a linux system
>> without knowing ufront whether the system uses pulse, ALSA or whatever?
>
> I would suggest libao:
> http://www.xiph.org/ao/
> and it's python bindings:
> http://nixbit.com/cat/multimedia/audio/libao/
Thanks a lot.
Yes, libao is a nice solution.
After having fixed some audio setup issues on my PC I have now the ALSA
and the libao solution working.
import ao
pcm = ao.AudioDevice("pulse", bits=16, rate=sample,
channels=1, byte_format=1)
pcmdata = create_pcmdata()
pcm.play(pcmdata)
--
http://mail.python.org/mailman/listinfo/python-list
Re: palindrome iteration
;) In [29]: s = 'bannab' In [30]: a = np.frombuffer(s.lower(), dtype='uint8') In [31]: np.all(a == a[::-1]) Out[31]: True In [32]: s = 'bannac' In [33]: a = np.frombuffer(s.lower(), dtype='uint8') In [34]: np.all(a == a[::-1]) Out[34]: False -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribute Non Library
narke writes: > My simple tool writing in python get bigger and bigger and I think I'd > better split my code into several files. But, unlike what in some other > languages, there is no way to compile these several files into a single > executable. Before I splitting my simple tool program, I just put it in > /usr/local/bin and run, very simple. Now I have to consider distribute > a lot of files in a whole. I know distutils can help, but I feel it is > a little uncomfortable, since I am not sharing a library, I am not > sharing any thing. I just want to refactory my code. Is there a better > solution to my case? Can I simply create a directory in /usr/local/bin > and put my script and other used files into the directory? Does > distutils help in this case? Consider using setuptools + console entry points. With these, you will automatically generate a shell-script to execute for your otherwise eggified and easy installable package. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribute Non Library
On Sep 11, 11:10 pm, narke wrote: > My simple tool writing in python get bigger and bigger and I think I'd > better split my code into several files. But, unlike what in some other > languages, there is no way to compile these several files into a single > executable. Sure there is. py2exe, py2app, cx_freeze, etc. -- http://mail.python.org/mailman/listinfo/python-list
Re: analysis of algoritms
On Sep 9, 11:22 pm, Alain Ketterlin wrote: > Baba writes: > > In below code "the outer loop test in step 4 will execute ( n + 1 ) > > times (note that an extra step is required to terminate the for loop, > > hence n + 1 and not n executions), which will consume T4( n + 1 ) > > time." (fromhttp://en.wikipedia.org/wiki/Analysis_of_algorithms) > > > 1 get a positive integer from input > > 2 if n > 10 > > 3 print "This might take a while..." > > 4 for i = 1 to n > > 5 for j = 1 to i > > 6 print i * j > > 7 print "Done!" > > > Why does step 4 execute n+1 times? what is the exta step mentioned > > above > > In "the outer loop test [...]", the important word is _test_. Line 4 has > to test the value of i against n, which results in true n times and in > false once (where it jumps to instruction 7). > > Note that this would be true even with python loops using range(n) or > xrange(n), where the test is not an integer comparison. > > (Note also how this last remark tries to avoid complete off-topic-ness > of this discussion in this group :-) > > -- Alain. Hi Alain Thanks for the explanation! Baba -- http://mail.python.org/mailman/listinfo/python-list
Issue 1 of "PET: English Translation" a Python magazine is out!
-- Forwarded message -- From: Roberto Alsina Date: Fri, Sep 10, 2010 at 12:00 AM Subject: [pyar] Issue 1 of "PET: English Translation" a Python magazine is out! To: [email protected], Python Argentina This magazine is a community effort. It's done by Python guys in Argentina. We are quite proud of it, and we hope you like it too. You can read Issue 1 in our webpage: http://revista.python.org.ar/1/html-en/ It's available in several different formats, including PDF, ePub, Mobipocket, HTML and FB2, and is released under a CC-by-nc-sa license. It has been translated to english by us, and we are not native speakers. Hopefully Shakespeare will not raise from his grave to slap us for grievous offense against his language! But, to save us from the Wrath of Wil, feel free to point out any mistakes and unhappy turns of phrase in the comments. Now that we have the english version out, we have *much bigger* plans for our second issue. We'll keep you posted. ___ pyar mailing list [email protected] http://listas.python.org.ar/listinfo/pyar PyAr - Python Argentina - Sitio web: http://www.python.org.ar/ -- Sebastián Bassi. Lic. en Biotecnologia. Curso de Python en un día: http://bit.ly/cursopython Python Book: www.py4bio.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribute Non Library
On 2010-09-12, Glazner wrote: > On Sep 12, 5:10 am, narke wrote: >> My simple tool writing in python get bigger and bigger and I think I'd >> better split my code into several files. But, unlike what in some other >> languages, there is no way to compile these several files into a single >> executable. Before I splitting my simple tool program, I just put it in >> /usr/local/bin and run, very simple. Now I have to consider distribute >> a lot of files in a whole. I know distutils can help, but I feel it is >> a little uncomfortable, since I am not sharing a library, I am not >> sharing any thing. I just want to refactory my code. Is there a better >> solution to my case? Can I simply create a directory in /usr/local/bin >> and put my script and other used files into the directory? Does >> distutils help in this case? >> >> Thanks in advance. > > try : > python mayApp.zip > > myApp.zip <--> all your files + a __main__.py file as a starting > point... looks also not decent :( i want my tool appear as an executabe, not an zip. but thank you anyway. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribute Non Library
narke writes: > On 2010-09-12, Glazner wrote: >> On Sep 12, 5:10 am, narke wrote: >>> My simple tool writing in python get bigger and bigger and I think I'd >>> better split my code into several files. But, unlike what in some other >>> languages, there is no way to compile these several files into a single >>> executable. Before I splitting my simple tool program, I just put it in >>> /usr/local/bin and run, very simple. Now I have to consider distribute >>> a lot of files in a whole. I know distutils can help, but I feel it is >>> a little uncomfortable, since I am not sharing a library, I am not >>> sharing any thing. I just want to refactory my code. Is there a better >>> solution to my case? Can I simply create a directory in /usr/local/bin >>> and put my script and other used files into the directory? Does >>> distutils help in this case? >>> >>> Thanks in advance. >> >> try : >> python mayApp.zip >> >> myApp.zip <--> all your files + a __main__.py file as a starting >> point... > > looks also not decent :( i want my tool appear as an executabe, not an > zip. but thank you anyway. Again: http://www.5dollarwhitebox.org/drupal/node/75 Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: is there a way to get the encoding of python file
On 9/12/10 4:14 AM, Stef Mientki wrote: hello, Is it possible to get the encoding of a python file from the first source line, (if there's any), after importing it ( with '__import__' ) # -*- coding: windows-1252 -*- The regular expression used to match the encoding declaration is given here: http://docs.python.org/reference/lexical_analysis.html#encoding-declarations -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Required RENT Marina and JLT, 050-8320722
Required RENT Marina and JLT, 050-8320722 Dear I have a client who is looking to Rent apartment :- 1. Dubai Marina and JLT :- Studio ,1Bed and 2 Bed only (any building) Please send me your direct availabilities, or call me, viewing tomorrow, thank you! Peter Wong F.H 王福兴 (个人注册RERA BRN: 8866) Dubai Mob 手提 : +971 50 83 20 722 Malaysia Mob : +6012-2956466 Fax传真 : +971 4 32 30 895 E-mail 电邮 : [email protected] Company 公司 : Pinky Real Estate Broker冰奇房地产 (公司注册RERA ORN: 1866) Website : http://groups.google.com/group/dubai-property-club/boxsubscribe?p=FixAddr&email&_referer Note: If you want to be removed from our contacts, just reply to this e-mail with REMOVE. The content of this email is only a guide. The information, prices and availability of the properties may change without prior notice -- http://mail.python.org/mailman/listinfo/python-list
Re: Static typing, Python, D, DbC
Bearophile writes: > I see DbC for Python as a way to avoid or fix some of the bugs of the > program, and not to perform proof of correctness of the code. Even if > you can't be certain, you are able reduce the probabilities of some > bugs to happen. I think DbC as envisioned by the Eiffel guy who coined (and trademarked) the term is that it's a static verification technique, marketing-speak annotating subroutines with pre- and post- conditions that can be checked with Hoare logic. Runtime checks wouldn't qualify as that. -- http://mail.python.org/mailman/listinfo/python-list
"pointlabel"-like function for Python: distribute text labels on a 2-d scatter plot to avoid overlapping labels
Hello. There is a function for R (http://bm2.genes.nig.ac.jp/RGM2/ R_current/library/maptools/man/pointLabel.html) to help with placing/ locating text labels in an optimized way so as to minimise some measure of text overlap (or likely text overlap). Has anyone written or ported such a thing for Python? Thanks, c -- http://mail.python.org/mailman/listinfo/python-list
Re: Static typing, Python, D, DbC
--- On Sun, 9/12/10, Paul Rubin wrote: > From: Paul Rubin > Subject: Re: Static typing, Python, D, DbC > To: [email protected] > Date: Sunday, September 12, 2010, 4:28 PM > Bearophile > writes: > > I see DbC for Python as a way to avoid or fix some of > the bugs of the > > program, and not to perform proof of correctness of > the code. Even if > > you can't be certain, you are able reduce the > probabilities of some > > bugs to happen. > > I think DbC as envisioned by the Eiffel guy who coined (and > trademarked) > the term is that it's a static verification technique, > marketing-speak > annotating subroutines with pre- and post- conditions that > can be > checked with Hoare logic. Runtime checks wouldn't > qualify as that. Eiffel throws an exception when a contract is violated. That is run time behavior, not static verification. -EdK Ed Keith [email protected] Blog: edkeith.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: "pointlabel"-like function for Python: distribute text labels on a 2-d scatter plot to avoid overlapping labels
> measure of text overlap (or likely text overlap). Has anyone written > or ported such a thing for Python? Hm (talking to myself)... the link I gave above has some references, and one of those includes some python code. Seems not packaged up yet for plots, but may be close: http://meta.wikimedia.org/wiki/Map_generator#Placing_labels Anything better? c -- http://mail.python.org/mailman/listinfo/python-list
Current install methodolgy eggs?
What is the currently favored installation process for Python applications? The last time I looked, it was eggs. Is that still true? Is there any integration of eggs and handling into the base Python distribution? Is PEP 376 intended for applications written in Python, or just the Python distribution? Any good links to source of information. I would like to instill the habit of using a decent install process for even the smallest of utilities. -- http://mail.python.org/mailman/listinfo/python-list
Re: How Python works: What do you know about support for negative indices?
In article <[email protected]>, Ben Finney wrote: >Neil Hodgson writes: >> >> There appear to be deliberate wraps at sentence end or automatic wraps >> to fit <80 columns. > >The automatic wraps in the code presented in the message are wrong. The >automatic wraps in the bullet point list are, if not wrong, at least >presumably unintended. That is considerably different from your original claim that the post contained formatting that was "long-short-long-short", aka comb formatting. >I hope that clears up what I meant in this case. The effort devoted to >explaining this issue far outweighs the burden it caused initially. I'll >try to be more explicit when presenting it in future, to forestall this. s/explicit/accurate/ Had you noted that some lines of code were wrapped short, I would have agreed with you, but I also would have noted that it's not a big deal. -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke -- http://mail.python.org/mailman/listinfo/python-list
Re: Current install methodolgy eggs?
Paul Watson writes: > What is the currently favored installation process for Python > applications? ‘python ./setup.py install’, using the standard library's Distutils library. Other third-party libraries build on top of that and are generally backward-compatible. > The last time I looked, it was eggs. Is that still true? I don't think eggs were ever the favoured distribution method. They are one *option* provided by Setuptools, but even then a so-called “sdist” (source distribution) is the favoured distribution format, installed using the above command. > Any good links to source of information. I would like to instill the > habit of using a decent install process for even the smallest of > utilities. This is a dream shared by many, but Distutils has much improvement to be done yet. Recently — the past couple of years — a lot of progress has been made on this front, and Python 3.x is getting many of the benefits; look up the “Distutils2” efforts for more. -- \ “That's all very good in practice, but how does it work in | `\ *theory*?” —anonymous | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Current install methodolgy eggs?
On 9/12/2010 3:40 PM, Ben Finney wrote: Paul Watson writes: What is the currently favored installation process for Python applications? ‘python ./setup.py install’, using the standard library's Distutils library. Other third-party libraries build on top of that and are generally backward-compatible. The last time I looked, it was eggs. Is that still true? I don't think eggs were ever the favoured distribution method. They are one *option* provided by Setuptools, but even then a so-called “sdist” (source distribution) is the favoured distribution format, installed using the above command. Any good links to source of information. I would like to instill the habit of using a decent install process for even the smallest of utilities. This is a dream shared by many, but Distutils has much improvement to be done yet. Recently — the past couple of years — a lot of progress has been made on this front, and Python 3.x is getting many of the benefits; look up the “Distutils2” efforts for more. There's some discussion of a common installer on the Python development group, but that's probably the wrong approach. A more effective approach would be something that takes a standard "setup.py" file and wraps it in a Windows installer file, an RPM file, or whatever the platform uses as standard. The "eggs" system never worked very well. It made too many assumptions about where various things were, and when it guessed wrong, you were stuck. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Current install methodolgy eggs?
On 13 September 2010 08:40, Ben Finney > wrote: > Paul Watson writes: > > > What is the currently favored installation process for Python > > applications? > > ‘python ./setup.py install’, using the standard library's Distutils > library. > I thought it was python setup.py install or ./setup.py install if you had the permissions set correctly. What distro are you using? Cheers, Xav -- http://mail.python.org/mailman/listinfo/python-list
Re: Static typing, Python, D, DbC
Paul Rubin: > I think DbC as envisioned by the Eiffel guy who coined (and trademarked) > the term is that it's a static verification technique, marketing-speak > annotating subroutines with pre- and post- conditions that can be > checked with Hoare logic. Runtime checks wouldn't qualify as that. The implementations of DbC in D and C# run their tests at run-time (but in theory an external tool may find a way to perform part of those tests at compile-time). A full implementation of DbC contains several other things beside preconditions and postconditions, see http://www.python.org/dev/peps/pep-0316/ (it misses few things like loop invariants and loop variants). For me DbC is useful almost as unit-testing (I use them at the same time), this is why in the original post I have said it's one of the things I miss most in Python. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Current install methodolgy eggs?
On 2010-09-12 16:40, Ben Finney wrote: This is a dream shared by many, but Distutils has much improvement to be done yet. Recently — the past couple of years — a lot of progress has been made on this front, and Python 3.x is getting many of the benefits; look up the “Distutils2” efforts for more. Many thanks for your comments, Ben. Looks like I should learn distutils well. I see the distutils2 work going on. I hope it is designed to work with Python 2.x. That would help it get some traction in existing packages. Most platforms have an installation methodology. Oracle Solaris (yea, hard for me to get use to as well) has pkgadd. Microsoft has the .msi installer. Do you think it would be possible to create a toolset that would produce installation kits in each of these forms? That would make the install conform with the standard platform installer. Is this worthwhile thinking about? -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribute Non Library
On 2010-09-12, Diez B. Roggisch wrote: > narke writes: > >> My simple tool writing in python get bigger and bigger and I think I'd >> better split my code into several files. But, unlike what in some other >> languages, there is no way to compile these several files into a single >> executable. Before I splitting my simple tool program, I just put it in >> /usr/local/bin and run, very simple. Now I have to consider distribute >> a lot of files in a whole. I know distutils can help, but I feel it is >> a little uncomfortable, since I am not sharing a library, I am not >> sharing any thing. I just want to refactory my code. Is there a better >> solution to my case? Can I simply create a directory in /usr/local/bin >> and put my script and other used files into the directory? Does >> distutils help in this case? > > Consider using setuptools + console entry points. With these, you will > automatically generate a shell-script to execute for your otherwise > eggified and easy installable package. > > Diez That's really attracting. I will try, thanks! -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke test post -- http://mail.python.org/mailman/listinfo/python-list
Re: Distribute Non Library
On 2010-09-12, CM wrote: > On Sep 11, 11:10 pm, narke wrote: >> My simple tool writing in python get bigger and bigger and I think I'd >> better split my code into several files. But, unlike what in some other >> languages, there is no way to compile these several files into a single >> executable. > > Sure there is. py2exe, py2app, cx_freeze, etc. Also good solution! Thanks for the help. And, cx_freeze looks even workable on my Linux. Great. -- Life is the only flaw in an otherwise perfect nonexistence -- Schopenhauer narke test post -- http://mail.python.org/mailman/listinfo/python-list
Re: Minimal-D
In message <[email protected]>, Kruptein wrote: > Hey I'm creating a program called minimal-d which brings together many > "things" you would otherwise use seperate to develop. These things > are a file-manager,text-editor,ftp-client and sql-client. We have that already. It’s called a ”Linux distro”. -- http://mail.python.org/mailman/listinfo/python-list
Anyone using python on Mint Linux ?
Just read that Mint is a fine version of Debian Linux. Any comments about python on this ? Thanks, Dave WB3DWE -- http://mail.python.org/mailman/listinfo/python-list
Re: Static typing, Python, D, DbC
Ed Keith writes: >> I think DbC as envisioned by the Eiffel guy... >> the term is that it's a static verification technique, > > Eiffel throws an exception when a contract is violated. That is run > time behavior, not static verification. The runtime checks are for when static analysis hasn't been supplied (that is usually a partly manual process). DBC is always intended to be statically verified as I understand it. Doing it at runtime is just a hackish fallback. -- http://mail.python.org/mailman/listinfo/python-list
Re: Anyone using python on Mint Linux ?
In article , wrote: > >Just read that Mint is a fine version of Debian Linux. >Any comments about python on this ? Why would there be? Either it works or it's broken, and given that it's Debian, I'd certainly bet that Python works. -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ [on old computer technologies and programmers] "Fancy tail fins on a brand new '59 Cadillac didn't mean throwing out a whole generation of mechanics who started with model As." --Andrew Dalke -- http://mail.python.org/mailman/listinfo/python-list
Re: Anyone using python on Mint Linux ?
On Sun, Sep 12, 2010 at 7:24 PM, wrote: > Just read that Mint is a fine version of Debian Linux. > Any comments about python on this ? > Thanks, Dave WB3DWE I used to do some of my development on Mint. Was happy with it then, and I suspect that the same would be true now. Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: Static typing, Python, D, DbC
* Paul Rubin, on 13.09.2010 04:50: Ed Keith writes: I think DbC as envisioned by the Eiffel guy... the term is that it's a static verification technique, Eiffel throws an exception when a contract is violated. That is run time behavior, not static verification. The runtime checks are for when static analysis hasn't been supplied (that is usually a partly manual process). DBC is always intended to be statically verified as I understand it. Doing it at runtime is just a hackish fallback. DBC can't in generally be statically checked. E.g. a precondition of a routine might be that its argument is a sorted array. So regarding the nature of the checks it's not hopelessly incompatible with Python. Cheers, - Alf -- blog at http://alfps.wordpress.com> -- http://mail.python.org/mailman/listinfo/python-list
Re: Static typing, Python, D, DbC
On 9/12/2010 7:50 PM, Paul Rubin wrote: Ed Keith writes: I think DbC as envisioned by the Eiffel guy... the term is that it's a static verification technique, Eiffel throws an exception when a contract is violated. That is run time behavior, not static verification. The runtime checks are for when static analysis hasn't been supplied (that is usually a partly manual process). DBC is always intended to be statically verified as I understand it. Doing it at runtime is just a hackish fallback. Right. Static verification is finally a production technology. All signed Windows 7 drivers must pass Microsoft's static checker, which checks that they don't have bad pointers and call all the driver APIs correctly. That's real "design by contract". It's not that relevant to Python, where you can't crash the underlying system. But it really matters in languages where you can. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Python script for MySQL Passwords Unreliable on first boot (rc.local)
The script below works great when logged in as root and run from the
command line, but when run at first boot using /etc/rc.local in Ubuntu
10.04, it fails about 25% of the time- the system root, mysql root and
some mysql user passwords are set correctly, but one will fail with
console log reporting standard mysql login error: "ERROR 1045 (28000):
Access denied for user 'root' @ 'localhost' (using password: YES)"
Is there something about running python scripts from init jobs that I
should account for, such as an environment variable?
#!/usr/bin/env python
# Udates system & MySQL root passwords on first boot
files = ['/home/ubuntu/passwords','/opt/data1/alfresco/extensions/
extension/alfresco-global.properties','/opt/data/etc/mysql/
debian.cnf','/home/ubuntu/duncil']
userpasswords = {'root':'ROOTPASSWORD'}
mysqlpasswords =
{'root':'MYSQLPASSWORD','alfresco':'alfrescoPASSWORD','debian-sys-
maint':'debian-sys-maintPASSWORD'}
otherpasswords = ['OTHERPASSWORD']
log = '/var/log/firstrun'
import random, string
import crypt
import re
from subprocess import PIPE, Popen
def getsalt(chars = string.letters + string.digits):
# generate a random 2-character 'salt'
return random.choice(chars) + random.choice(chars)
def getpwd(chars = string.letters + string.digits, len = 12):
retval = "";
for i in range(0, len):
# generate 12 character alphanumeric password
retval += random.choice(chars)
return retval
def replace_pass(filename):
handle = open(filename, 'r')
hbuf = handle.read()
handle.close()
for placeholder, password in pdict.iteritems():
hbuf = re.sub(placeholder, password, hbuf)
try:
# Output file
handle = open(filename, 'w')
handle.write(hbuf)
handle.close()
except:
pass
#logh.write('failed to update ' + filename + "\n")
#logh.write('maybe you don\'t have permision to write to it?
\n')
logh = open(log, "a")
logh.write("Starting...\n")
# Generate passwords
pdict = {}
for user, placeholder in userpasswords.iteritems():
syspass = getpwd()
Popen(['usermod', '--password', crypt.crypt(syspass, getsalt()),
user])
logh.write(placeholder + ": User " + user + " --> " + syspass +
"\n")
pdict[placeholder] = syspass
# What's the MySQL Root password placeholder?
mplace = mysqlpasswords['root']
for user, placeholder in mysqlpasswords.iteritems():
mpass = getpwd()
if (("root" in mysqlpasswords) and (mysqlpasswords['root'] in
pdict)):
mrootpass = pdict[mysqlpasswords['root']]
else:
mrootpass = ""
Popen(['mysql', '-uroot', "--password=" + mrootpass, "-e", "UPDATE
user SET Password = PASSWORD('" + mpass + "') WHERE User = '" + user +
"';FLUSH PRIVILEGES;","mysql"])
logh.write(placeholder + ": MySQL " + user + " --> " + mpass +
"\n")
pdict[placeholder] = mpass
for placeholder in otherpasswords:
opass = getpwd()
logh.write(placeholder + ": " + opass + "\n")
pdict[placeholder] = opass
# Update passwords
for file in files:
logh.write("Replacing placeholders in " + file + "\n")
replace_pass(file)
logh.write("Finished\n")
logh.close
--
http://mail.python.org/mailman/listinfo/python-list
Re: Minimal-D
On Sep 13, 3:23 am, Lawrence D'Oliveiro wrote: > In message > <[email protected]>, Kruptein > wrote: > > > Hey I'm creating a program called minimal-d which brings together many > > "things" you would otherwise use seperate to develop. These things > > are a file-manager,text-editor,ftp-client and sql-client. > > We have that already. It’s called a ”Linux distro”. Well I didn't know that although I use it perhaps daily? -- http://mail.python.org/mailman/listinfo/python-list
Re: Static typing, Python, D, DbC
On 9/12/2010 4:28 PM, Paul Rubin wrote: Bearophile writes: I see DbC for Python as a way to avoid or fix some of the bugs of the program, and not to perform proof of correctness of the code. Even if you can't be certain, you are able reduce the probabilities of some bugs to happen. I think DbC as envisioned by the Eiffel guy who coined (and trademarked) the term is that it's a static verification technique, marketing-speak annotating subroutines with pre- and post- conditions that can be checked with Hoare logic. Runtime checks wouldn't qualify as that. Programming by contract as popularized by Bertrand Meyer (that Eiffel guy) was designed for run-time checks because that's when errors show. Programming by contract is based on Dijkstra's weakest precondition work. http://www.scss.tcd.ie/Edsko.de.Vries/talks/weakest_precondition.pdf During the last five years before my hands went bad, I spent significant amount of time working with formal methods and simpler concepts such as design by contract. Design by contract made the last five years of my programming career the most rewarding it had ever been. It was nice to finally write code that was significantly, and measurably better than those coded using Brown 25 (another fine product from Uranus)[1]. one of the common mistakes have seen about programming by contract or design by contract is that people assume it's a proof of correctness. It's not, it's an experiential proof that the code is executing correctly to the extent that you've characterized the pre-and post-conditions. Formal proofs are considered a dead-end as far as I can tell but it's been a good number of years since I've really investigated that particular domain. If my opinion is worth anything to anyone, I would highly recommend adopting some form of programming by contract in everything you write. use the properties that Dijkstra taught us with the weakest precondition to test only what you need to test. If you are careless, assertions can build up to a significant percentage of the code base and Slow execution. the argument for dealing with this, last time I looked, was that you turn off assertions when your code is "running". This logic is flawed because bugs exist and will assert themselves at the worst possible time which usually means after you turned off the assertions. Personally, I see assertions as another form of defensive programming. If you can define preconditions as excluding bad data, then your mainline body becomes faster/smaller. Anyway, this debate was going on circa 1990 and possibly even earlier when Dykstra wrote his first papers. Consider me a double plus vote for strong programming by contract capability in Python. If I can ever get programming by voice working in a reasonable way, I might even be able to use it. :-) PS, to explain Brown 25 in case you weren't watching "those damn kids" comedy movies in the 1970s with a bunch of very stoned friends. Thank God for campus buses keeping us out of cars. [1] http://www.youtube.com/watch?v=008BPUdQ1XA -- http://mail.python.org/mailman/listinfo/python-list
Meeting in October
Meeting in October? Chris Mahan (818) 671-1709 http://christophermahan.com/ [email protected] http://twitter.com/chris_mahan -- http://mail.python.org/mailman/listinfo/python-list
