Re: ERROR:root:code for hash md5 was not found
I had that problem after moving my Python installation into another directory. Reinstalling Python helped. -- http://mail.python.org/mailman/listinfo/python-list
a beginner, beginners question
Hello, I'm trying to learn python programming and so far so good. However when trying to master the oop side I ran into a small problem. I think I've done everything ok as outlined below. But I just don't understand why the `method' of `class' example isn't printing any of the variables that I have set earlier on ? Could someone please explain to me what it is I am doing wrong ? Thank you so much ! #!/usr/bin/env python class example: def __init__(self, foo, bar): self.foo = foo self.bar = bar def method(self): print "method ... :" print self.foo print self.bar if __name__ == "__main__": obj = example obj.foo = "var1" obj.bar = "var2" obj.method -- http://mail.python.org/mailman/listinfo/python-list
Re: a beginner, beginners question
On Wed, 19 Mar 2008 05:57:04 -0500, Tim Chase wrote:
>> class example:
>> def __init__(self, foo, bar):
>> self.foo = foo
>> self.bar = bar
>>
>> def method(self):
>> print "method ... :"
>> print self.foo
>> print self.bar
>>
>> if __name__ == "__main__":
>> obj = example
>
> This makes "obj" a synonym for "example". You want to instantiate your
> "example" class with
>
>obj = example("Some foo", "Some Bar")
>
>> obj.foo = "var1"
>> obj.bar = "var2"
>
> which then makes these two lines either unneeded or an overwriting of
> the initialization
>
>> obj.method
>
> and this returns a function, not the results of the function. You need
> to call it
>
>obj.method()
>
> -tkc
Ok thank you for elaborating I think I've got it.
Thnkx. !
--
http://mail.python.org/mailman/listinfo/python-list
beginners question about return value of re.split
Hello,
I have a question regarding the return value of re.split() since I have
been unable to find any answers in the regular sources of documentation.
Please consider the following:
#!/usr/bin/env python
import re
if __name__ == "__main__":
datum = "2008-03-14"
the_date = re.split('^([0-9]{4})-([0-9]{2})-([0-9]{2})$', datum, 3)
print the_date
Now the result that is printed is:
['', '2008', '03', '14', '']
My question: what are the empty strings doing there in the beginning and
in the end ? Is this due to a faulty regular expression ?
Thank you !
KL.
--
http://mail.python.org/mailman/listinfo/python-list
Re: beginners question about return value of re.split
On Fri, 21 Mar 2008 10:31:20 -0500, Tim Chase wrote: <..> Ok thank you ! I think I got a bit lost in all the possibilities python has to offer. But your answers did the trick. Thank you all again for responding and elaborating. Cheers, KL. -- http://mail.python.org/mailman/listinfo/python-list
Re: beginners question about return value of re.split
On Fri, 21 Mar 2008 13:34:27 -0700, John Machin wrote:
> On Mar 22, 2:53 am, klaus <[EMAIL PROTECTED]> wrote:
>> On Fri, 21 Mar 2008 10:31:20 -0500, Tim Chase wrote:
>>
>> <..>
>>
>> Ok thank you !
>>
>> I think I got a bit lost in all the possibilities python has to offer.
>
> IMHO you got more than a bit lost. You seem to have stumbled on a
> possibly unintended side effect of re.split.
>
> What is your underlying goal?
>
> If you want merely to split on '-', use datum.split('-').
>
> If you want to verify the split results as matching patterns (4 digits,
> 2 digits, 2 digits), use something like this:
>
> | >>> import re
> | >>> datum = '2008-03-14'
> | >>> pattern = r'^(\d\d\d\d)-(\d\d)-(\d\d)\Z' You may notice two
> differences between my pattern and yours ...
> | >>> mobj = re.match(pattern, datum) | >>> mobj.groups()
> | ('2008', '03', '14')
>
> But what are you going to do with the result? If the resemblance between
> '2008-03-14' and a date is not accidental, you may wish to consider
> going straight from a string to a datetime or date object, e.g.
>
> | >>> import datetime
> | >>> dt = datetime.datetime.strptime(datum, '%Y-%m-%d')
> | >>> dt
> | datetime.datetime(2008, 3, 14, 0, 0)
> | >>> d =
> datetime.datetime.date(dt)
> | >>> d
> | datetime.date(2008, 3, 14)
>
> HTH,
> John
Ok, sorry for my late reply. I got caught up in a fight with easterbunnys
over some extraordinary large, fruitty and fertile eggs. Some creatures
take Easter just to serious and it is not even mating season ! Can you
believe that ?
:-)
Anyway, the underlying goal was to verify user input and to split up the
date so that I could easily convert it to another format. Among others,
an url and for a database querry. And I have succeeded in that.
Thank you again; for taking the time to explain - and to question.
KL.
--
http://mail.python.org/mailman/listinfo/python-list
Py 3.6 tarfile
Hi,
if I understand the documentation of the tarfile module correctly writing
TarfileObject.add(".../path/to/filename", recursive=False)
means that the directory structure of the file object will not be included
in the archive.
In the following script only "testtext1.pdf" is stored outside a directory
structure. The other files are always stored in a directory structure;
using recursive=False does not have any effect.
#!/usr/bin/env python3
#
import argparse
import sys
import tarfile
import os
arch = "Archive.tgz"
os.unlink(arch)
try:
TO = tarfile.open(name=arch, mode='x:gz') # Tarfile object
TO.add("testtext1.pdf")
TO.add("./testtext2.pdf")
TO.add("./testtext3.pdf", recursive=False)
TO.add("./files/testtext4.pdf")
TO.add("./files/testtext5.pdf", recursive=False)
TO.close()
except FileExistsError as err:
pass
=
Is my understanding correct or what do have to do so that the files are
stored without any directory information?
Thanks for any hints.
--
K.D.J.
--
https://mail.python.org/mailman/listinfo/python-list
_Py_FatalErrorFunc not found
I need some help. hplip as of late complains : File "/usr/bin/hp-scan", line 40, in import scanext ImportError: /usr/lib/python3.9/site-packages/scanext.so: undefined symbol: _Py_FatalErrorFunc Which module defines this _Py_FatalErrorFunc? Or has the name of this function changed in python-3.9.1? If yes what is its name now? hplip version is the latest, hplip-3.20.11, but they have not taken notice of the problem as far as i know. Any help is much appreciated -- Klaus -- https://mail.python.org/mailman/listinfo/python-list
Installing Python 3.8.3 with tkinter
Hi, Trying to install Python 3.8.3 with tkinter I run configure with the following options ./configure --enable-optimizations --with-ssl-default-suites=openssl --with-openssl=/usr/local --enable-loadable-sqlite-extensions --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6' --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include' Running Python gives the following information Python 3.8.3 (default, Jul 22 2020, 11:52:15) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> import tkinter Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.8/tkinter/__init__.py", line 36, in import _tkinter # If this fails your Python may not be configured for Tk ModuleNotFoundError: No module named '_tkinter' >>> Obviously there is something wrong with my configure options. How do that correctly? Thanks for any help. K.D.J. -- https://mail.python.org/mailman/listinfo/python-list
Re: Installing Python 3.8.3 with tkinter
On 7/22/20 11:05 PM, Ned Deily wrote: On 2020-07-22 06:20, Klaus Jantzen wrote: Trying to install Python 3.8.3 with tkinter I run configure with the following options ./configure --enable-optimizations --with-ssl-default-suites=openssl --with-openssl=/usr/local --enable-loadable-sqlite-extensions --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6' --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include' Running Python gives the following information [...] How do that correctly? Try --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib -ltcl8.6 -ltk8.6' Thank you for your suggestion; unfortunately it did not help. -- https://mail.python.org/mailman/listinfo/python-list
[SOLVED] Re: Installing Python 3.8.3 with tkinter
On 7/22/20 12:20 PM, Klaus Jantzen wrote: Hi, Trying to install Python 3.8.3 with tkinter I run configure with the following options ./configure --enable-optimizations --with-ssl-default-suites=openssl --with-openssl=/usr/local --enable-loadable-sqlite-extensions --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6' --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include' Running Python gives the following information Python 3.8.3 (default, Jul 22 2020, 11:52:15) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> import tkinter Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.8/tkinter/__init__.py", line 36, in import _tkinter # If this fails your Python may not be configured for Tk ModuleNotFoundError: No module named '_tkinter' >>> Obviously there is something wrong with my configure options. How do that correctly? Thanks for any help. K.D.J. In my post I forgot to mention that I am running PY under Debian Buster. As suggested by Ned Deily I switched to PY 3.8.5 After some more research in the internet I found that the tcl/tk libraries have automaticalle been installed during the Buster installation. For automatically including tkinter during the PY installation one needs also the 'tk-dev toolkit'. With that I did not need the options '--with-tcltk-libs'/'--with-tcltk-includes' After the installation of PY 3.8.5 I can import tkinter. Thank you very much for your replies. K.D.J. -- https://mail.python.org/mailman/listinfo/python-list
Syntax question
Hi, the other day I came across the book "Classic Computer Science Problems in Python" by David Kopec. The function definitions in the examples like = def fib2(n: int) -> int: if n < 2: # base case return n return fib2(n - 2) + fib2(n - 1) # recursive case if __name__ == "__main__": print(fib2(5)) print(fib2(10)) = use a syntax that I have never seen on this list or in other publications. My questions: Is that new? Is is 'recommended' to use this is the future? I can only see a certain advantage of using this type of function definition in resp. to the documentation, as it does not provide an automatic check of the type of the argument(s) or of the result as in Java. -- K.D.J. -- https://mail.python.org/mailman/listinfo/python-list
helpviewer and a wxpython application crash
Hi @all, I've implement a python application with boa constructor and wx.python. Now I wanted to add a help to my application. I found the helpviewer, where it is very easy to open a helpbook. So I've create an helpbook with boa constructor and then I open the book with the helpviewer. That's all no problem. It works fine, but when I open the helpbook in my application, I have a problem when I exit it. There MS Windows Error Report dialog box is open, this means my application crashes, when I close it. If I don't open the helpbook in my application, it shutdown correctly. Why did it crash, when I open the helpbook in it? I'm using python v2.4.1, wx.python v2.6.1.0 and boa constructor v0.4.4 on windows XP. thanks for any help. greets Klaus -- http://mail.python.org/mailman/listinfo/python-list
fast list lookup
Hello, what is the fastest way to determine whether list l (with len(l)>3) contains a certain element? Klaus -- http://mail.python.org/mailman/listinfo/python-list
wxnotebook and tooltips
Hi, I've implemented a wxnotebook on my application. I can set a tooltip for the complete notebook, but I want to set for every page a tooltip, so that the user can get additionally information over it before he change it. Is this possible with python and wxwidgets? Thanks for any help. Greets Klaus -- http://mail.python.org/mailman/listinfo/python-list
py2exe 0.6.2 version resources
Hi @all,
I've implementet a simple setup script for my application with py2exe.
The setup.py works fine, but now I want to add version resources to my
*.exe-file. But how can I do it?
I've tested it with the setup.cfg, but that doesn't work. I alwayse
became the errormessage:
error: error in setup.cfg: command 'py2exe' has no such option
'version_legalcopyright'
until I've deleted all options.
I'm using python 2.4.1 and py2exe 0.6.2 on Windows XP SP2.
Thanks for any help.
Greets,
Klaus
PS:
Here my example setup.py:
from distutils.core import setup
import glob
import py2exe
install = dict(script="startApp.py",
dest_base="My Application",
icon_resources=[(1, "img\\icon.ico")])
opts = dict(py2exe= dict(dist_dir="Application"))
setup(name = 'My Application',
author="Klaus Rödel",
data_files=[("img", glob.glob("img\\*.png")), ("img",
glob.glob("img\\*.ico")), ("", ["my_dll.dll"])],
options = opts,
windows=[install])
And here my example setup.cfg:
[py2exe]
version-companyname=which ever
version-filedescription=the little application name
version-fileversion=0.1.0
version-legalcopyright=Hmm...
version-legaltrademarks=blah blah
version-productname=the little applications product name
version-productversion=0.1.0
--
http://mail.python.org/mailman/listinfo/python-list
list of all type names
Hello, Python has one feature that I really hate: There are certain special names like 'file' and 'dict' with a predefined meaning. Yet, it is allowed to redefine these special names as in dict = [1:'bla'] In order to avoid problems in the future, I tried to get the list of all those names, but I could not find it. (The Python Reference Manual only says that there is the type "Dictionary" in Python, but not that 'dict' is a semi-reserved word.) Can you point me to such a list? Klaus -- http://mail.python.org/mailman/listinfo/python-list
Re: RELEASED Python 2.4 (final)
Anthony Baxter schrieb: happy to announce the release of Python 2.4. Thanks! minor remarks: First line from C:\Python24\README.txt This is Python version 2.4 alpha 3 In C:\Python24\Tools in various subdirs the README.TXT files disappeared. -- regards kgm -- http://mail.python.org/mailman/listinfo/python-list
gather information from various files efficiently
Hello, I need to gather information that is contained in various files. Like so: file1: = foo : 1 2 bar : 2 4 baz : 3 = file2: = foo : 5 bar : 6 baz : 7 = file3: = foo : 4 18 bar : 8 = The straightforward way to solve this problem is to create a dictionary. Like so: [...] a, b = get_information(line) if a in dict.keys(): dict[a].append(b) else: dict[a] = [b] Yet, I have got 43 such files. Together they are 4,1M large. In the future, they will probably become much larger. At the moment, the process takes several hours. As it is a process that I have to run very often, I would like it to be faster. How could the problem be solved more efficiently? Klaus -- http://mail.python.org/mailman/listinfo/python-list
Thanks (Re: gather information from various files efficiently)
Hello, (Sorry for beginning a new thread. Google does not allow me to reply to my own posting. And I cannot use a newsreader at the moment.) Thanks to all who participated in the thread. I tried the try- and the if-solution. The setdefault-solution didn't work in my program. With the try-solution the process took 37 seconds. With the if-solution the process took so much time that I didn't bother to wait. Klaus -- http://mail.python.org/mailman/listinfo/python-list
RE: Python Users Nederland - python-nl mailing list
Ik zal aan deze bijeenkomst deelnemen. Ik ben de developer van SimPy (Simulation in Python). Als er belangstelling bestaat, kan ik op een van de toekomstige meetings een presentatie over SimPy geven. Klaus Müller simpy.sourceforge.net > -Original Message- > From: Johannes Gijsbers [mailto:[EMAIL PROTECTED] > Sent: Tuesday, December 21, 2004 9:32 PM > To: [EMAIL PROTECTED] > Subject: Python Users Nederland - python-nl mailing list > > Python Users Nederland, PUN, houdt haar tweede meeting op dinsdag 11 > januari om > 20.00. > > "Agenda" > > > We beginnen om 20.00 met een presentatie van 1-1,5 van Martijn Faassen. > Hij zal > spreken over de Zope 3 component architectuur, met misschien een aantal > uitweidingen over Five (Zope 3 in Zope 2). Na de presentatie kunnen we > uitwijken naar één van de kroegen rond het Leidseplein. > > Locatie > --- > > De locatie is in principe het kantoor van Amaze (http://www.amaze.nl), > maar als > blijkt dat er veel belangstelling is (>15/20) dan kunnen we waarschijnlijk > uitwijken naar een ruimte van XS4ALL. Meldt het dus als je van plan bent > te > komen. > > Over PUN > > > Python Users Nederland is een beginnende gebruikersgroep. We hebben een > website > (http://www.py.nl) en een mailinglist > (http://mail.python.org/mailman/listinfo/python-nl). De mailinglist wordt > ook > gebruikt om Nederlandse Python-gebruikers voor andere projecten op te > sporen. > > Cheers, > > Johannes -- http://mail.python.org/mailman/listinfo/python-list
SQLite
Hello, I have downloaded Python3.5.1 as .targz, compiled it(configure, make,...) and it works (under Debian Wheezy AMD64) up to the moment I wanted to use SQLite. I get the following message: === jantzen@PC4:~$ python Python 3.5.0 (default, Dec 2 2015, 14:16:16) [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in from sqlite3.dbapi2 import * File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in from _sqlite3 import * ImportError: No module named '_sqlite3' === Obviously something is missing. How do I solve the problem? Where do I find this module? Thanks for a hint. -- K.D.J. -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLite
On 02/21/2016 10:37 PM, Albert-Jan Roskam wrote: (Sorry for top posting) IIRC, you have to do sudo apt-get install build-essential python-dev ... then re-compile python > To: [1][email protected] > From: [2][email protected] > Subject: SQLite > Date: Sun, 21 Feb 2016 18:11:18 +0100 > > Hello, > > I have downloaded Python3.5.1 as .targz, compiled it(configure, make,...) > and it works > (under Debian Wheezy AMD64) up to the moment I wanted to use SQLite. > > I get the following message: > === > jantzen@PC4:~$ python > Python 3.5.0 (default, Dec 2 2015, 14:16:16) > [GCC 4.7.2] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import sqlite3 > Traceback (most recent call last): > File "", line 1, in > File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in > > from sqlite3.dbapi2 import * > File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in > from _sqlite3 import * > ImportError: No module named '_sqlite3' > === > > Obviously something is missing. > How do I solve the problem? Where do I find this module? > > Thanks for a hint. > -- > > K.D.J. > -- > [3]https://mail.python.org/mailman/listinfo/python-list Hello, thanks for your hint. That did it!!! -- K.D.J. References Visible links 1. mailto:[email protected] 2. mailto:[email protected] 3. https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLite
On 02/22/2016 02:44 AM, Chris Angelico wrote: On Mon, Feb 22, 2016 at 8:37 AM, Albert-Jan Roskam [1] wrote: IIRC, you have to do sudo apt-get install build-essential python-dev ... then re-compile python That may well work, but it's probably easier to work this way: sudo apt-get build-dep python3 That should grab all the compilation dependencies of the python3 package, which on Wheezy is a 3.2 IIRC. The deps haven't changed since then AFAIK. When you build, you should get a summary at the end that tells you about any modules that couldn't be built. The most common reason for that is missing deps. If you still have any after running the above, post here and we may be able to more directly advise. ChrisA That did not work because I did not install Python 3.5. with apt-get but downloaded the source and compiled myself. Thus apt-get does not have any information about the Python 3.5 installation. I got it to work following the hint by Albert-Jan Roskam. -- K.D.J. References Visible links 1. mailto:[email protected] -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLite
On 02/22/2016 09:32 AM, Klaus Jantzen wrote: On 02/21/2016 10:37 PM, Albert-Jan Roskam wrote: (Sorry for top posting) IIRC, you have to do sudo apt-get install build-essential python-dev ... then re-compile python > To: [[1]1][email protected] > From: [[2]2][email protected] > Subject: SQLite > Date: Sun, 21 Feb 2016 18:11:18 +0100 > > Hello, > > I have downloaded Python3.5.1 as .targz, compiled it(configure, make,...) > and it works > (under Debian Wheezy AMD64) up to the moment I wanted to use SQLite. > > I get the following message: > === > jantzen@PC4:~$ python > Python 3.5.0 (default, Dec 2 2015, 14:16:16) > [GCC 4.7.2] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import sqlite3 > Traceback (most recent call last): > File "", line 1, in > File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in > > from sqlite3.dbapi2 import * > File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in > from _sqlite3 import * > ImportError: No module named '_sqlite3' > === > > Obviously something is missing. > How do I solve the problem? Where do I find this module? > > Thanks for a hint. > -- > > K.D.J. > -- > [3][3]https://mail.python.org/mailman/listinfo/python-list Hello, thanks for your hint. That did it!!! At least on one machine!!! -- K.D.J. References Visible links 1. [4]mailto:[email protected] 2. [5]mailto:[email protected] 3. [6]https://mail.python.org/mailman/listinfo/python-list On the second machine (DELL E6530) I have everything in the installation directory (the expansion of the tarball): sqlite directory with all the modules. I ran the apt-get install as suggested above. I ran './configure --enable-loadable-sqlite-extensions' and find the appropriate entry in the configure.log. I ran 'make' and find the configure option in the Makefile. But when running 'make test' the sqlite test fails with 'no _sqlite3 module' Any helpful ideas? Thanks. -- K.D.J. References Visible links 1. mailto:1][email protected] 2. mailto:2][email protected] 3. https://mail.python.org/mailman/listinfo/python-list 4. mailto:[email protected] 5. mailto:[email protected] 6. https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
RE: Is htmlGen still alive?
Thank you for this input. I was primarily looking for a download site. I downloaded HyperText and definitely will give it a try. It looks good. Klaus > -Original Message- > From: Gabriel Genellina [mailto:[EMAIL PROTECTED] > Sent: Tuesday, December 19, 2006 8:49 PM > To: [EMAIL PROTECTED] > Cc: [email protected] > Subject: Re: Is htmlGen still alive? > > At Monday 18/12/2006 17:37, [EMAIL PROTECTED] wrote: > > >Does anybody know whether htmlGen, the Python-class library for > >generating HTML, is still being maintained? Or from where it can be > >downloaded? The Starship site where it used to be hosted is dead. > > *active* in what sense? HTML std doesn't change all days, and > being a python only library, the only changes would be due to > compatibility issues or adopting new language features of new > python versions. > BTW, I like HyperText more than htmlgen. > > > -- > Gabriel Genellina > Softlab SRL > > > > > > > __ > Pregunta. Respondi. Descubrm. > Todo lo que quermas saber, y lo que ni imaginabas, > esta en Yahoo! Respuestas (Beta). > !Probalo ya! > http://www.yahoo.com.ar/respuestas > > -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Ken Tilton <[EMAIL PROTECTED]> writes: > > Sure, but where does the infection thing come in? Suppose RMS > publishes a new library call add-42, whose api is add-42, inputs n, > outputs n+42, source left as an exercise, and Kenny decides he can use > it, it is great. Now if Kenny uses it in his commercial software, commercial software can be free as well, such as the GNU Ada compiler. > add-42 does not somehow become less free to ride 'neath the starry > skies above, don't fence me in. But RMS wants Kenny's hide. Nothing > Kenny wrote derived from add-42, but RMS wants it all. that's because it's immoral not to give it all > Kenny happened > to solve the traveling salesman problem and protein-folding and passed > the fricking Turing test by using add-42 wherever he needed 42 added > to a number, and RMS wants credit and ownership and control of it > all. He and his license shall now dictate access and use of all that > code. The handcuffs are on, and they are inscribed "free". of course they are free > > No wonder the GPL has gone nowhere. Freely. RMS reasonably wanted that > add-42 not get co-opted, but that in no way necessitated the land grab > that is GPL. The GPL is a gratuitous reach only fancifully justified > by wanting to ensure that open source remain open. which is necessary in a moral culture. Only an immoral culture may accept non-disclosure > So this has nothing > to do with freedom in /any/ sense of the word, it has to do with a > political agenda opposed to the idea of private property. > private property is unethical Klaus Schilling -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
Ken Tilton <[EMAIL PROTECTED]> writes: > > Oh, I missed that. I just saw something about software should be > shared of course it should, as otherwise it would be immoral, > and programmers should be content with an hourly wage, not > sales. > only greedy creeps wouldn't be content Klaus Schilling -- http://mail.python.org/mailman/listinfo/python-list
Re: The Modernization of Emacs: terminology buffer and keybinding
George Neuner writes: > > Or, how about politics? Another example from the Judeo-Christian > Bible (that is, from the Old Testament), politicking was the sin that > resulted in Lucifer's fall from God's grace. that's not a God, but an inferior demiurge, as correctly figured by Marcion > [Yeah, I know the official story is that Lucifer's sin was envy. the official story is thoroughly flawed. of course Lucifer means carrier of light, and thus has nothing to do with sin. but the contrary. Lucifer brings enlightenment to those people who are enchained in the darkness of oppression and stupor the demiurge imposed upon them. Thus it's Plato who equalled the situation of unenlightened mankind with that of prisoners in a dark cave. Sin is the rejection of the light brought by the carrier of light. Same goes for those who have once seen the light of the Symbolic Expressions, but continue rejoycing in infix Syntax. Klaus Schilling -- http://mail.python.org/mailman/listinfo/python-list
pickling a circular object inherited from list
Hello everyone,
I have a problem with inheritance from list. I want to create a tree
like object where child nodes are kept in self[:] and every child has a
field that points to its parent. Pickling such an object, however,
throws an AssertionError. See below for source code and output of an
easy example case of my problem.
What did I do wrong?
Best regards,
Klaus
source:
class myList(list):
pass
class myObject:
def __init__(self, parent=None):
self.parent = parent
if __name__ == '__main__':
r = myList()
r.append( myObject(r) )
from pickle import dump, load
dump(r, file('/tmp/x', 'w'))
= output:
Traceback (most recent call last):
File "", line 1, in ?
File "/tmp/python-11053-o.py", line 15, in ?
dump(r, f)
File "/usr/lib/python2.4/pickle.py", line 1382, in dump
Pickler(file, protocol, bin).dump(obj)
File "/usr/lib/python2.4/pickle.py", line 231, in dump
self.save(obj)
File "/usr/lib/python2.4/pickle.py", line 338, in save
self.save_reduce(obj=obj, *rv)
File "/usr/lib/python2.4/pickle.py", line 419, in save_reduce
self.memoize(obj)
File "/usr/lib/python2.4/pickle.py", line 251, in memoize
assert id(obj) not in self.memo
AssertionError
--
http://mail.python.org/mailman/listinfo/python-list
Re: pickling a circular object inherited from list
What did I do wrong? Old Python version? :) Seems to work in 3.0 (don't have 2.6 currently to check but IMO it's fixed there as well). It works for me with v3.0 as well, but not with v2.6.1 (same error as stated before for v2.4). Is there any way to fix this in v2.6.1 or even v2.4? Right now I cannot switch to v3.0 because I depend on several not compatible packages (numpy, biopython, ...) -- http://mail.python.org/mailman/listinfo/python-list
Re: pickling a circular object inherited from list
Ned Deily wrote: In article <[EMAIL PROTECTED]>, Klaus Kopec <[EMAIL PROTECTED]> wrote: What did I do wrong? Old Python version? :) Seems to work in 3.0 (don't have 2.6 currently to check but IMO it's fixed there as well). It works for me with v3.0 as well, but not with v2.6.1 (same error as stated before for v2.4). Is there any way to fix this in v2.6.1 or even v2.4? Right now I cannot switch to v3.0 because I depend on several not compatible packages (numpy, biopython, ...) It looks like your example can be made to work by either specifying pickle protocol 2 or by switching to cPickle. Using pickle protocol 2 solved the problem. Thank you all for helping me out! -- http://mail.python.org/mailman/listinfo/python-list
use strings to call functions
Hello,
I am writing a program that analyzes files of different formats. I
would like to use a function for each format. Obviously, functions can
be mapped to file formats. E.g. like this:
if file.endswith('xyz'):
xyz(file)
elif file.endswith('abc'):
abc(file)
...
Yet, I would prefer to do something of the following kind:
func = file[-3:]
apply_func(func, file)
Can something of this kind be done in Python?
Klaus
--
http://mail.python.org/mailman/listinfo/python-list
Re: use strings to call functions
>
> A file extension is not necessarily 3 chars long.
No, of course not. But it is, if I choose to use only (self-made) file
endings that are 3 chars long. Anyway, it was just an example.
> handlers = {
> ".txt" : handle_txt,
> ".py" : handle_py,
> # etc
> }
>
That is exactly what I would like to avoid: Having to map the function
'handle_txt' to '.txt'. Firstly, because I don't want to repeat
anything and secondly, because I will one day add a new function and
forget to add its name to the dictionary. (This is not severe if there
is only one dictionary for mapping functions, but it will make life a
lot harder, if a lot of mappings of this kind are used.)
What I want is calling the string directly. In Prolog, I would use
something like:
get_file_ending(File, Ending),
Predicate =.. [Ending, File],
call(Predicate).
--
http://mail.python.org/mailman/listinfo/python-list
Re: use strings to call functions
> go to hell ;-), it is part of the language, it seems to match the > aforementioned question. Thats right. In fact, your code is the precise analogy of my Prolog example in Python. Obviously, eval() and call() are both inherently dangerous. They should never be used in programs that are used in programs that get input from people other than the author. Yet, my program is supposed to parse files that I have created myself and that are on my laptop. It is not supposed to interact with anybody else than me. On the other hand, I think, it is worthwhile getting acquainted with the getattr-stuff, because this method can be useful in many contexts. Anyway, thanks to all who participated in this thread. It taught me a lot. -- http://mail.python.org/mailman/listinfo/python-list
Re: use strings to call functions
On Feb 9, 11:01 am, Stefan Behnel wrote: > KlausNeuner, 09.02.2010 10:04: > > > my program is supposed to parse files that I have created myself and that > > are on my laptop. It is not supposed to interact with anybody else > > than me. > > Famous last words. > > Stefan All right, I admit that eval() is evil and should never be used. Under no circumstances. (Which is, of course, the reason, why Python has eval().) The same applies to knives. You shouldn't use them. You shouldn't even use them in your own kitchen. A man might enter your kitchen, take your knife away and use it against you. -- http://mail.python.org/mailman/listinfo/python-list
Re: use strings to call functions
On Feb 10, 12:55 pm, Bruno Desthuilliers wrote: > KlausNeunera écrit : > > > > > All right, I admit that eval() is evil and should never be used. > > Can you tell the difference between your above statement and the following: As already pointed out in my second post (though perhaps not explicitly enough), I like the getattr-stuff better than eval(). That is why I will not use eval(). I don't have a reason to use eval(). All I wanted to say is this: If there are no circumstances at all under which eval() can reasonably be used, then it should not be part of Python. As it is part of Python (and as Python is a carefully designed language), there will most probably some situations in which one might want to use it. -- http://mail.python.org/mailman/listinfo/python-list
Re: use strings to call functions
> Or perhaps is it me that failed to re-read a bit more of the thread > before answering - I obviously missed the irony (and made an a... of > myself), sorry :-/ There is nothing to be sorry about. I am grateful to all participants of this thread. I know a lot more about Python than before. -- http://mail.python.org/mailman/listinfo/python-list
Recompilation of Python3.6.x
Hello, in order to have the Python-SQLite support available one has to recompile Python. For the recompiliation to succeed a number of 'modules/libs' have to be present. In the internet I found the following list build-essential libz-dev libreadline-dev libncursesw5-dev libssl-dev libgdbm-dev libsqlite3-dev libbz2-dev liblzma-dev tk-dev libdb-dev libc6-dev zlib After having installed these 'modules/libs' I recompiled Python3.6.1 and although the steps 'make', 'make test', and 'make install' produced some errors the sqlite3-support is available. My question: Is this list complete or are there superfluous items? My suggestion: Couldn't such a list be provided in the README file? -- K.D.J. -- https://mail.python.org/mailman/listinfo/python-list
Re: Recompilation of Python3.6.x
On 03/22/2017 06:34 PM, Thomas Nyberg wrote: On 03/22/2017 12:42 PM, Klaus Jantzen wrote: Hello, in order to have the Python-SQLite support available one has to recompile Python. For the recompiliation to succeed a number of 'modules/libs' have to be present. In the internet I found the following list build-essential libz-dev libreadline-dev libncursesw5-dev libssl-dev libgdbm-dev libsqlite3-dev libbz2-dev liblzma-dev tk-dev libdb-dev libc6-dev zlib After having installed these 'modules/libs' I recompiled Python3.6.1 and although the steps 'make', 'make test', and 'make install' produced some errors the sqlite3-support is available. My question: Is this list complete or are there superfluous items? My suggestion: Couldn't such a list be provided in the README file? If you're using Ubuntu/debian, you could use `sudo apt-get build-dep python3.5` (might need another version depending upon what you have in your package manager). What that does is install the packages required to build the debian packages. Unless any new libraries are needed for 3.6, you should be good. I did not know somenthing like this exists. I can't speak for the maintainers, but I don't think that providing such a list is super reasonable considering that there are many different OSs which have sometimes have slightly different library package names (though of course one could argue that Ubuntu/debian helps a lot of people). Cheers, Thomas With the above my suggestion is superfluous. Thanks a lot for the information. -- K.D.J. -- https://mail.python.org/mailman/listinfo/python-list
Re: Recompilation of Python3.6.x
On 03/23/2017 12:23 AM, Jon Ribbens wrote: On 2017-03-22, Grant Edwards wrote: On 2017-03-22, Thomas Nyberg wrote: On 03/22/2017 03:22 PM, Jon Ribbens wrote: A simple table with a list of the library names, the debian package names, and the rpm names would provide the information in a way that would be useful to everyone. A _simple_ table would be useful. However, a _simple_ table is not possible. I definitely agree, but it would be kind of difficult to maintain. I mean if you supported debian and redhat (should others be considered?), And you would need table for each _version_ of each distribution (libraries sometimes get combined/renamed/split). Not really, that's why I suggested one of the fields in the table would be the standard library name - people should always be able to use that to find the appropriate package for their distribution (if there is one, otherwise they'll need to compile from source). And you would need tables showing which libraires are required for which Python features: tkinter is optional, crypto is optional (or at least used to be), etc. That's a good idea - that would make the simple table have 4 columns: name, deb, rpm, python module (or "essential"). The information must be somewhere because Python must have been compiled frequently and correctly for the various (important) OSs before making it available to the public. And I do not think that it is left up to "your luck" that the required packages and libraries are present. -- K.D.J. -- https://mail.python.org/mailman/listinfo/python-list
NNTP module capable of "MODE STREAM"
Hi, I need a Python NNTP module that is capable of doing "MODE STREAM" as client and as server. Does anyone here know of such a module except the twisted.protocols.nntp module? Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://streetkids.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacing utf-8 characters
Mike wrote:
> Hi, I am using Python to scrape web pages and I do not have problem
> unless I run into a site that is utf-8. It seems & is changed to
> & when the site is utf-8.
>
> [...]
> Any ideas?
How about using the universal feedparser from feedparser.org to fetch
and parse the RSS from Reuters? That's what I do and it works like a
charm.
#v+
>>> import feedparser
>>> rss = feedparser.parse('http://today.reuters.com/rss/topNews')
>>> for what in ('link', 'title', 'summary'):
... print rss.entries[0][what]
... print
...
http://today.reuters.com/news/newsarticle.aspx?type=topNews&storyid=2005-10-05T193846Z_01_DIT561620_RTRUKOC_0_US-COURT-SUICIDE.xml
Top court seems closely divided on suicide law
During arguments, the justices sharply questioned both sides on whether
then-Attorney General John Ashcroft had the power under federal law in 2001 to
bar distribution of controlled drugs to assist suicides, regardless of state
law.
>>>
#v-
Cheers,
--
Klaus Alexander Seistrup
Magnetic Ink, Copenhagen, Denmark
http://magnetic-ink.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: How do you do this in python?
[EMAIL PROTECTED] wrote: > perl -e 'print "Hello, world\n"' python -c 'print "Hello, world"' Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I create a dir using Python?
Sumi wrote: > How do i create a dir using python. #v+ os.makedirs = makedirs(name, mode=511) makedirs(path [, mode=0777]) Super-mkdir; create a leaf directory and all intermediate ones. Works like mkdir, except that any intermediate path segment (not just the rightmost) will be created if it does not exist. This is recursive #v- Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to convert a "long in a string" to a "long"?
Carsten Haese wrote:
>> OK, this is what I want, so I tried
>>
>> s = long("0xL")
>> ValueError: invalid literal for long(): 0xL
>>
>> s = long("0x")
>> ValueError: invalid literal for long(): 0xL
>>
>> What can I do?
>>
>> Thank you in advance.
>> Stefan
>
> Leave out the "0x" prefix and tell long() that you're using
> base 16:
>
>>>> long("", 16)
> 4294967295L
It's sufficient to tell long() that you're using base 16:
#v+
>>> long('0xL', 16)
65535L
>>>
#v-
Cheers,
--
Klaus Alexander Seistrup
Copenhagen, Denmark
http://seistrup.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Reading a subprocesses stdout on Windows
BroLewis wrote: > I have been trying for several weeks now to write a program that > allows me to read the stdout of a process that I spawn and once > I receive feedback, act appropriately. Have you looked into the 'commands' module? Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Why use #!/usr/bin/env python rather than #!python?
Adriano Ferreira wrote: > Many Python scripts I see start with the shebang line > > #!/usr/bin/env python > > What is the difference from using just > > #!python #v+ $ ls -l /tmp/hello.py -rwxr-xr-x 1 klaus klaus 38 2005-12-02 14:59 /tmp/hello.py $ cat /tmp/hello.py #! python print 'Hello, world!' # eof $ /tmp/hello.py bash: /tmp/hello.py: python: bad interpreter: No such file or directory $ #v- Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://streetkids.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Why use #!/usr/bin/env python rather than #!python?
Adriano Ferreira skrev: >> #v+ >> >> $ ls -l /tmp/hello.py >> -rwxr-xr-x 1 klaus klaus 38 2005-12-02 14:59 /tmp/hello.py >> $ cat /tmp/hello.py >> #! python >> print 'Hello, world!' >> # eof >> $ /tmp/hello.py >> bash: /tmp/hello.py: python: bad interpreter: No such file or directory >> $ >> >> #v- > > Hey, that's not fair. In your illustration above, does 'python' can be > found in the PATH? That is, > > $ python /tmp/hello.py > > works? If it does, probably > > #!/usr/bin/python > #!/usr/bin/env python > #!python > > would also work if > (1) 'python' is at '/usr/bin/python' (but that's inflexible) > (2) 'python' can be found in the environment variable path (if 'env' > is at '/usr/bin/env') > (3) 'python' can be found in the environment variable path (no need > for 'env' utility) Sure, I wasn't fair. But look here: #v+ $ python /tmp/hello.py Hello, world! $ which python /usr/bin/python $ #v- I do not know the syntax of the shebang-line, but perhaps an absolute path is required? PS: The "Mail-Copies-To: nobody" header line means that I do not wish to receive mail replies - please follow-up to group only. Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://streetkids.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Why use #!/usr/bin/env python rather than #!python?
Adriano Ferreira wrote: > So that "#!/usr/bin/env python" is more portable than "#! python" > and that's probably why it worked for me with cygwin/bash but not > for Klaus on whatever platform he used. /me is using bash on linux. > I agree. Only a very strange Unix-like installation would not have > 'env' at '/usr/bin/env'. According to <http://www.in-ulm.de/~mascheck/various/shebang/>: »However, env(1) is not /usr/bin/env but /bin/env at least on Unicos 9.0.2, OpenServer 5.0.6 and IIRC on at least one older Linux distribution. Free-, Net- and OpenBSD in turn only come with /usr/bin/env. So the env-mechanism is increasing conven- ience, but not strictly assuring portability.« Cheers, -- Klaus Alexander Seistrup PNX · http://pnx.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with "lambda x : print x/60,x%60"
Justin Ezequiel wrote: > Try > > lambda_hrs = lambda x: (x/60,x%60) Or #v+ lambda_hrs = lambda x: divmod(x, 60) #v- Cheers, -- Klaus Alexander Seistrup PNX · http://pnx.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Learning Python...
Falc wrote: > So if you have any books you could reccomend me that would rock, I > can't really afford a book so if online that would be excellent. Have you looked into: <http://wiki.python.org/moin/BeginnersGuide> <http://python.org/doc/Intros.html> Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: database in python ?
[EMAIL PROTECTED] wrote: > I need to build table which need searching data which needs more > power then dictionary or list in python, can anyone help me what > kind of database suitable for python light and easy to learn. Is > mySQL a nice start with python ? You could try SQLite for Python: <http://pysqlite.org/>. Cheers, -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python 2.3.2 for PalmOS available
[EMAIL PROTECTED] wrote: > Some months ago i did a port of the Python2.3.2 interpreter to > PalmOS. Wow, this is just what I've been waiting for. Meanwhile I've tried to make do with Rexx for PalmOS, hehehe... However, MLPY doesn't seem to work on my Tungsten T3 (PalmOS 5.2.1). The .prc installs without any problems, and I can start the Python interpreter, but nothing happens if I ring in a Python expression and press return -- the prompt just "hangs" and never returns. Any ideas? -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode "em space" in regex
Xah Lee :
> how to represent the unicode "em space" in regex?
>
> e.g. i want do something like this:
>
> fracture=re.split(r'\342371*\|\342371*',myline,re.U)
I'm not sure what you're trying to do, but would it help you to use
it's name:
>>> EM_SPACE = u'\N{EM SPACE}'
>>> fracture = myline.split(EM_SPACE)
?
Cheers,
--
Klaus Alexander Seistrup
Magnetic Ink, Copenhagen, Denmark
http://magnetic-ink.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Parse command line options
Hue wrote:
> try:
>
> opts,args = getopt.getopt(sys.argv[1:], 'n:t:h:i:o:',
> ["Number=","time=","help=","image_file=","Output Filename="])
>
> except getopt.GetoptError:
> print 'Unrecognized argument or option'
> usage()
> sys.exit(0)
Proceed with e.g.:
#v+
for (opt, arg) in opts:
if opt in ('-n', '--No'):
do_no()
elif opt in ('-t', '--Time'):
do_time()
# [...]
else:
barf(opt, arg)
# end if
# end for
#v-
But be consistent when using long options: use all lowercase, use either
dashes or underscores (not both), don't use whitespace.
I usually do something like:
#v+
Options = {
'i:': 'input=',
'o:': 'output=',
'c' : 'copyright',
'h' : 'help',
'v' : 'version',
}
shortOpts = ''.join(Options.keys())
longOpts = Options.values()
# [...]
try:
(opts, args) = getopt.getopt(argv[1:], shortOpts, longOpts)
except getopt.error, msg:
die(msg)
# end try
# [...]
for (opt, arg) in opts:
# Handle all options
:
# end for
#v-
Additional, non-option, arguments will be in the "args" variable.
Cheers,
--
Klaus Alexander Seistrup
Magnetic Ink, Copenhagen, Denmark
http://magnetic-ink.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python 2.3.2 for PalmOS available
Lucio Torre wrote: > Make sure you write the expression in the lower text-area, and > then press the send button. This should do it. Ah, that's the trick! It wasn't obvious that there were two text areas, and I intuitively wrote commands at the python prompt. Problem solved. Say, are floats implemented? Comparisons seem to work, but print'ing doesn't: #v+ >>> 1.0 > 0.5 True >>> print 1.23 %.*g >>> #v- -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting argv to variable
Tom skrev: > newDirectory = str(sys.argv[1:]) Try newDir = '/'.join(sys.argv[1:]) or newDir = sys.argv[1] or for newDir in sys.argv[1:]: : or something along those lines, depending on how you wish to interpret the commandline. Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://surdej.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: List splitting
Steven skrev: > For the purposes of this question, the list will be: > > t = [ "a", "b", "c", "n", "a", "a", "t", "t", "t" ] > > Now, I know that every 3rd element of the list belongs together: > > Group 1 = 0, 3, 6 > Group 2 = 1, 4, 7 > Group 3 = 2, 5, 8 > > I'm trying to sort this list out so that I get a list of lists > that contain the correct elements: > > Goal = [ [ "a", "n", "t"], [ "b", "a", "t"], > ["c", "a", "t" ] ] #v+ >>> t = [ "a", "b", "c", "n", "a", "a", "t", "t", "t" ] >>> [t[i::3] for i in range(3)] [['a', 'n', 't'], ['b', 'a', 't'], ['c', 'a', 't']] >>> #v- Cheers, -- Klaus Alexander Seistrup SubZeroNet, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: unescape HTML entities
Rares Vernica wrote:
> How can I unescape HTML entities like " "?
>
> I know about xml.sax.saxutils.unescape() but it only deals with
> "&", "<", and ">".
>
> Also, I know about htmlentitydefs.entitydefs, but not only this
> dictionary is the opposite of what I need, it does not have
> " ".
How about something like:
#v+
#!/usr/bin/env/python
'''dehtml.py'''
import re
import htmlentitydef
myrx = re.compile('&(' + '|'.join(htmlentitydefs.name2codepoint.keys()) + ');')
def dehtml(s):
return re.sub(
myrx,
lambda m: unichr(htmlentitydefs.name2codepoint[m.group(1)]),
s
)
# end def dehtml
if __name__ == '__main__':
import sys
print dehtml(sys.stdin.read()).encode('utf-8')
# end if
#v-
E.g.:
#v+
$ echo 'frække frølår' | ./dehtml.py
frække frølår
$
#v-
--
Klaus Alexander Seistrup
Copenhagen, Denmark, EU
http://klaus.seistrup.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Unescape HTML entities
Rares Vernica wrote: > How does your code deal with ' like entities? It doesn't, it deals with named entities only. But take a look at Fredrik's example. Cheers, -- Klaus Alexander Seistrup København, Danmark, EU http://klaus.seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Member index in toples
A.M skrev:
> I have a tuple like this:
>
> T = ("One","Two","Three","Four")
>
> Is there any built-in way to find what is the index of "Two"
> withouot looping within the tuple?
>
> Is the same feature available for lists or dictionaries?
Lists have an index method:
#v+
>>> L = list(T)
>>> L.index('Three')
2
>>>
#v-
Dictionaries are unordered and hence indices don't make much sense.
Mvh,
--
Klaus Alexander Seistrup
SubZeroNet, Copenhagen, Denmark
http://magnetic-ink.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Missing unicode data?
Hi group,
I just came across the following exception:
#v+
$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import unicodedata
>>> u'\N{LATIN LETTER SMALL CAPITAL BARRED B}'
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 0-38:
unknown Unicode character name
>>> unicodedata.name(u'\u1d03')
Traceback (most recent call last):
File "", line 1, in ?
ValueError: no such name
>>> ^D
$
#v-
When checking unicodedata.name() against each uchar in the file
/usr/share/unidata/UnicodeData-4.0.1d1b.txt that came with the
console-data package on my Ubuntu Linux installation a total of
1226 unicode characters seems to be missing from the unicodedata
module (2477 missing characters when checking against the latest
database from unicode.org¹). Is this a deliberate omission?
Cheers,
Klaus.
¹) http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
--
Klaus Alexander Seistrup
SubZeroNet, Copenhagen, Denmark
http://magnetic-ink.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: Missing unicode data?
Fredrik Lundh skrev: > I'm pretty sure unicodename.name() doesn't look in the Unicode- > Data file on your machine, nor in the latest file from unicode.org. I am pretty sure of that, too. I was only using those files as a reference against the unicode data that comes with my python interpreter. > in other words, you get whatever version that was used to create > the Unicode data set in your Python distribution. I see. > iirc, 2.4 uses Unicode 3.2, and 2.5 uses Unicode 4.1. to update, > use the tools under Tools/unicode. Thanks for the hint. Mvh, -- Klaus Alexander Seistrup SubZeroNet, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to extract 2 integers from a string in python?
[EMAIL PROTECTED] skrev: > how can I extract 2 integers from a string in python? > > for example, my source string is this: > Total size: 173233 (371587) > > I want to extract the integer 173233 and 371587 from that > soource string, how can I do that? E.g.: #v+ >>> import re >>> re.findall(r'\d+', 'Total size: 173233 (371587)') ['173233', '371587'] >>> #v- Mvh, -- Klaus Alexander Seistrup Copenhagen, Denmark http://surdej.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Blog source code in Python
Lazy Lad wrote: > Is there a blog application source available in Python? Several. Did you try Google before you posted your question? The search term "python blog" has <http://wiki.python.org/moin/PythonBlogSoftware> within the first 10 hits. Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://surdej.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you use this list?
Grant Edwards wrote: > Find an NNTP server and read it as a newsgroup. Or Google Groups: http://groups.google.com/group/comp.lang.python Cheers, -- Klaus Alexander Seistrup Dyssegård, Denmark http://surdej.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I avoid abusing lists?
[EMAIL PROTECTED] wrote: > if histogram.has_key(s): > histogram[s] += 1 > else: > histogram[s] = 1 I wonder if histogram[s] = histogram.get(s, 0) + 1 would be more efficient... Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://ipsum.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to sort list
Fredrik Lundh wrote: > note that DSU is built into Python these days: > > L.sort(key=transform) Sweet, thanks for the hint. Cheers, -- Klaus Alexander Seistrup http://klaus.seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Remarkable results with psyco and sieve of Eratosthenes
Pekka Karjalainen wrote: > You can omit the call to math.sqrt if you test this instead. > > y*y > x > > in place of if y > maxfact: . Or use sqrt = lambda x: x ** .5 Cheers, -- Klaus Alexander Seistrup http://klaus.seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF8 & HTMLParser
Jan Danielsson wrote:
>However, I would like to convert the "text" (which is utf8)
> to latin-1. How do I do that?
How about:
latin = unicode(text, 'utf-8').encode('iso-8859-1')
Please see help(u''.encode) for details about error handling. You
might also want to trap errors in a try-except statement.
Cheers,
--
Klaus Alexander Seistrup
http://klaus.seistrup.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: shell command needs whitespace characters escaped
Metaperl wrote: > I downloaded a file which has a space in the filename. I want > to run a shell unzip on it, but it fails in my current code: > > syscmd = "cd %s ; unzip %s" % (self.storage.input, file.basename()) > os.system(syscmd) > > because no escaping was done. Using "cd '%s' ; unzip '%s'" as your formatting string should work. Cheers, -- Klaus Alexander Seistrup http://klaus.seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: nntplib downloads content with extra linebreaks
Rweth wrote:
> I am using nntplib to download archived xml messages from our
> internal newsgroup. This is working fine except the download
> of files to the connected server, has extra embedded lines in
> them (all over the place), from the
>s.body(id,afile) # body method
The 'linebreaks' are probably '\r\n' pairs, so you could do a
buf.replace('\r\n', '\n')
to convert all such pairs to single LFs (buf being the buffer or
string that holds the text with 'linebreaks').
Cheers,
--
Klaus Alexander Seistrup
http://klaus.seistrup.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: nntplib downloads content with extra linebreaks
Rweth wrote:
>for aline in buf:
> bufHeal.append(aline.replace('\r\n', '\n'))
What does one single aline look like?
> s.body(id,afile)
Does the 'afile' contain a filename or a filepointer?
Cheers,
--
Klaus Alexander Seistrup
http://klaus.seistrup.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: nntplib downloads content with extra linebreaks
Rweth wrote: > so afile contains a filename. > One single aline looks like so: >'' Beats me where those empty lines come from, it doesn't seem to happen in nntplib. Does the same thing happen if you pass .body() a filepointer? Cheers, -- Klaus Alexander Seistrup http://klaus.seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Making dir's
Or os.makedirs(): #v+ >>> import os >>> print os.makedirs.__doc__ makedirs(path [, mode=0777]) Super-mkdir; create a leaf directory and all intermediate ones. Works like mkdir, except that any intermediate path segment (not just the rightmost) will be created if it does not exist. This is recursive. #v- Cheers, -- Klaus Alexander Seistrup Copenhagen, Denmark http://seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Locale and cookies
[EMAIL PROTECTED] wrote: > I tried to fix this by changing the locale back to "English" > before creating cookies and that works on Windows but not for > Linux. If I use "en_EN.ISO8859-1" it works on Linux but not > on Windows. How about setting locale to "C" or "POSIX"? -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: popen2 psql
Mage wrote: > I tried to write a proxy script for "psql" command. I need some > query log. I failed to read from the file object. The psql command is probably linked against readline; did you look in the ~/.psql_history file? Cheers, -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: WordPress Python Library 1.0
Michele Ferretti wrote: > ok, sorry, but subject is very explicit! Still, it's insufficient for those of us who doesn't know what WordPress is, and it's a waste of time for those of us who don't speak Italian. C'mon, pal, you can do much better than that! -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: WordPress Python Library 1.0
Michele Ferretti wrote: > ok, sorry, but subject is very explicit! Still, it's insufficient for those of us who don't know what WordPress is, and it's a waste of time for those of us who don't speak Italian. C'mon, pal, you can do much better than that! -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python & SQLite
dcrespo wrote: > Does PySQLite run on Linux? There are specific python modules for SQLite on Linux. -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: A Faster Way...
[EMAIL PROTECTED] wrote: > If I simplify the problem, suppose I have 2 lists like: > > a = range(10) > b = range(20,30) > > What I would like to have, is a "union" of the 2 list in a > single tuple. In other words (Python words...): > > c = (0, 20, 1, 21, 2, 22, 3, 23, 4, 24, 5, 25, . If the order is unimportant you could use: #v+ >>> tuple(set(range(10)) | set(range(20,30))) (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29) >>> #v- Cheers, -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading files into a 2D list.
Øyvind Østlund wrote: > I have a list of about 20 files that I want to read line by > line into a 2D list. So the first dimension will be each file, > and the second every line in that file. > > I tried to do something like this: > > files_and_lines = [][] > filenumber = 0 > > for files in file_names: > try: > lexi_file = open(str(sys.path[0]) + "/lexi/" + files, "r") > files_and_lines[filenumber] = lexi_file.readlines() > filenumber = filenumber + 1 > > except(IOError): > print "Something went wrong trying to read the file:" > print "'" + str(sys.path[0]) + files + "'" I'm not sure I understand you. Do you wish to end up with an array like this: #v+ [fileName0][fileLines0] [fileName1][fileLines1] ... [fileNameN][fileLinesN] #v- In that case try something like: #v+ >>> files_and_lines = [] >>> for name in file_names: >>> files_and_lines.append([name, open(name, 'r').readlines()]) >>> print 'Read %d files' % (len(files_and_lines),) #v- Add proper error checking. At least, I think the [].append() method is what you're looking for. Cheers, -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Null String Variable
Rotary wrote: > I want to say something like that: if msg is empty ...then do > something. So how can i figure that msg is empty string (no > character, msg = ''). #v+ if not msg: print 'msg is empty' #v- -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: where to find the doc about python regular expression?
ÒÊÃÉɽÈË wrote: > thanks Did you try Google: <http://www.google.com/search?q=python+regular+expressions> First hit is: <http://www.amk.ca/python/howto/regex/> -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.path
HMS Surprise wrote: > Have I misused .extend? The .extend() method expects an iterable, try .append() instead. Cheers, -- Klaus Alexander Seistrup http://klaus.seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: List Moderator
Grant Edwards wrote: > Maybe I've got a beter news server, but I don't see much > spam at all in c.l.p. Neither do I. Cheers, -- Klaus Alexander Seistrup http://klaus.seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: number generator
Raymond Hettinger wrote: > To make the solutions equi-probable, a simple approach is to > recursively enumerate all possibilities and then choose one > of them with random.choice(). Or create a list using the biased method, then use .shuffle() to return another permutation. Cheers, -- Klaus Alexander Seistrup Tv-fri medielicensbetaler http://klaus.seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: IP address
Scripter47 wrote:
> How do i get my ip address?
>
> in cmd.exe i just type "ipconfig" then it prints:
> ...
> IP-address . . . . . . . . . . . . . . . . . : 192.168.1.10
> ...
> how can i do that in python??
#v+
python -c 'import re, urllib; print re.findall("Your IP: (.+?)",
urllib.urlopen("http://myip.dk/";).read())[0]'
#v-
Cheers,
--
Klaus Alexander Seistrup
http://klaus.seistrup.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: IP address
Scripter47 wrote:
>> python -c 'import re, urllib; print re.findall("Your IP:
>> (.+?)", urllib.urlopen("http://myip.dk/";).read())[0]'
>
> Hmm then you need Internet connecting.
That's what IP adresses are for...
> can i do it without that?
Perhaps you could use the method mentioned in
http://mail.python.org/pipermail/python-list/1999-August/009153.html
> and it doesn't work either :(
Works for me:
#v+
[EMAIL PROTECTED]:~ $ python -c 'import re, urllib; print
re.findall("Your IP: (.+?)",
urllib.urlopen("http://myip.dk/";).read())[0]'
217.157.1.202
[EMAIL PROTECTED]:~ $
#v-
Cheers,
--
Klaus Alexander Seistrup
http://klaus.seistrup.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: IP address
Adam wrote:
> This will get your IP address:
>
> ###Code
> print socket.gethostbyaddr(socket.gethostname())
> ('compname', [], ['192.168.1.2'])
> End Code
It will return an IP address, but not necessarily the one you want:
#v+
[EMAIL PROTECTED]:~ $ python -c 'import socket; print
socket.gethostbyaddr(socket.gethostname())'
('zdani.szn.dk', [], ['2001:1448:89::1'])
[EMAIL PROTECTED]:~ $
#v-
Cheers,
--
Klaus Alexander Seistrup
http://klaus.seistrup.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: IP address
Colin J. Williams wrote: > Your one-liner doesn't work for me, with Windows XP, but the > following does, within Python. Could it be due to shell-escaping issues? I don't know anything about Windows... Cheers, -- Klaus Alexander Seistrup http://klaus.seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find out a date/time difference
Lad skrev: > How can I find out the date/time difference ( in days) of such > two fields? Did you try to subtract one value from the other? Mvh, -- Klaus Alexander Seistrup SubZeroNet, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find out a date/time difference
Nico Grubert skrev: > you could do this: > > >>> a = datetime.datetime(2006, 5, 24, 16, 1, 26) > >>> b = datetime.datetime(2006, 5, 20, 12, 1, 26) > >>> a-b > datetime.timedelta(4) > # 4 days Or #v+ >>> print (a-b).days 4 >>> #v- Mvh, -- Klaus Alexander Seistrup SubZeroNet, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Generating random passwords ... for a csv file with user details
Kanthi skrev:
> I have a csv file which in taken as the input file for adding
> users in my linux mail server with the format
>
> userid,fullname,passwword,dateofbith
>
> Now I have to write a script to generate random password in the
> password field for each user. A simple algorithm is sufficient
> for passwords
#v+
>>> import sha
>>> sha.sha('userid,fullname,passwword,dateofbith').digest().encode('base64')[:10]
'q0nCDQ1YdL'
>>>
#v-
Mvh,
--
Klaus Alexander Seistrup
SubZeroNet, Copenhagen, Denmark
http://magnetic-ink.dk/
--
http://mail.python.org/mailman/listinfo/python-list
Re: filter list fast
Lars Woetmann wrote: > I have a list I filter using another list and I would like > this to be as fast as possible > right now I do like this: > > [x for x in list1 if x not in list2] > > i tried using the method filter: > > filter(lambda x: x not in list2, list1) > > but it didn't make much difference, because of lambda I guess > is there any way I can speed this up If you use a reasonably new python version, you could use sets: #v+ >>> a = set(range(10)) >>> a set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> b = set(range(5, 15)) >>> b set([5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) >>> a.difference(b) set([0, 1, 2, 3, 4]) >>> a-b set([0, 1, 2, 3, 4]) >>> list(a-b) [0, 1, 2, 3, 4] >>> #v- Cheers, -- Klaus Alexander Seistrup SubZeroNet, Copenhagen, Denmark http://magnetic-ink.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Python Installation -- configure flags
I have not installed python for a long time so I am not sure whether the following configure flags are sufficient/recommandable for a Python3.12.11 installation. --prefix=/opt --with-lto --enable-optimizations --enable-loadable-sqlite-extensions --with-ensurepip=install --with-pydebug --with-assertions My current Debian Bookworm automatically installed/updated to Python 3.11.2; I do not want to change that. -- K.D.J. -- https://mail.python.org/mailman3//lists/python-list.python.org
