cannot find object instance
 (152 Views)
hi,
i am a python newbie..while trying out some message passing between
two object instances i came across a problem
moduleA.py
--------------------
import moduleB
class MyClassA:
def __init__(self):
self.age=0
self.address=''
def createClassB(self):
self.objB=moduleB.MyClassB()
def validate(self,age,address):
if(age >= 100 or address==''):
self.age=20;
self.address="Broadway,NewYork"
self.objB.display(self.age,self.address)
def callB(self):
self.objB.execute()
if __name__ == "__main__":
objA=MyClassA()
objA.createClassB()
objA.callB()
moduleB.py
------------------
import moduleA
class MyClassB:
def __init__(self):
self.createA()
def createA(self):
self.objA=moduleA.MyClassA()
def execute(self):
self.objA.validate(111,'')
def display(self,age,address):
print 'displaying:',str(age),address
when i run the code i get a message
AttributeError: MyClassA instance has no attribute 'objB'
Do i have to put a placeholder for objB in __init__ of MyClassA
is that why i get this errorsomeone please tell me how i can solve
this I tried to put self.objB=None but it didn't work..(i was
thinking of java style objB=NULL )
please help
|
Re: os.system()- cannot add parameter
 (146 Views)
En Wed, 20 Aug 2008 04:20:15 -0300, aditya shukla
escribi:
> I have a program which is in the form of a client-server. i wanna send
> the
> parameters from my python script such that the client passes it to the
> server.this is what i have done
> Server is running in vmplayer.This is what i have done
> b="c:\progs"
> os.system('start c:\\pnew\\xyz\\win32\\xyz' + " " + b) -- now this runs
> the
> xyz.exe but does not accept the parameter, where as if i directly give
>
> xyz c:\progs through the client(from cmd.exe) then this works.
I'd use the most basic debugging tools - print and repr:
b="c:\progs" # ensure it is correctly escaped
cmdline = 'start c:\\pnew\\xyz\\win32\\xyz' + " " + b
print repr(cmdline)
os.system(cmdline)
--
Gabriel Genellina
|
studieren und arbeiten im ausland Drogist Drogistin beruf auslandjobboerse oesterreich soziale arbeiten im ausland jobboerse hannoverstellenangebote lehrer ausland beruf ausland Creative Director
 (140 Views)
studieren und arbeiten im ausland Drogist Drogistin beruf ausland
jobboerse oesterreich soziale arbeiten im ausland jobboerse hannover
stellenangebote lehrer ausland beruf ausland Creative Director
+
+
+
ARBEITSANGEBOTE IM AUSLAND http://WWW.STELLENANGEBOT-AUSLAND.DE http://WWW.STELLENANGEBOT-AUSLAND.DE
+
+
+
AUSLANDSJOBS ONLINE FINDEN http://WWW.AUSLANDSJOBS-24.DE http://WWW.AUSLANDSJOBS-24.DE
+
+
+
ARBEITSANGEBOTE IM AUSLAND http://WWW.ARBEITSANGEBOTE-AUSLAND.DE http://WWW.ARBEITSANGEBOTE-AUSLAND.DE
+
+
+
ARBEITSANGEBOTE IN DEUTSCHLAND http://WWW.ARBEITSANGEBOT-DEUTSCHLAND.DE http://WWW.ARBEITSANGEBOT-DEUTSCHLAND.DE
+
+
+
STELLENANGEBOTE IN DEUTSCHLAND http://WWW.STELLENANGEBOT-DEUTSCHLAND.DE http://WWW.STELLENANGEBOT-DEUTSCHLAND.DE
+
+
+
Rechtsanwaeltin Rechtsanwalt jobboerse stellenboerse Lacklaborant
Lacklaborantin Mechatroniker Mechatronikerin stellenanzeigen ausland
Psychologe Psychologin arbeitsstellen ausland arbeiten als koch im
ausland Kellner Kellnerin krankenversicherung arbeit im ausland job
ins ausland
|
cannot load index value from mysql database
 (160 Views)
Hi
I am trying to right a script to keep a local copy of my mysql
database in a local access file. I was able to do this in Access
visual basic, but cannot get it to work in python.
The procedure works by storing the last index value after each
update. Then I do a quarry for all records with a index value bigger
the the last one stored.
In python when I try to get the index value, ID it gives me a
keyword. I know the firled exist because I am doing the following
querry
Here is the code,
Help!!!!!!
engine = win32com.client.Dispatch("DAO.DBEngine.36")
self.db=engine.OpenDatabase(r"w:\consulting\custom-web-stats-
project\web-stat.mdb")
access = self.db.OpenRecordset("select * from local_web_stat
where 1")
temp = self.db.OpenRecordset("select * from lastid where 1")
self.lastid=temp.Fields("lastid").Value
#open mysql
conn = MySQLdb.connect (" .")
cursor = conn.cursor (MySQLdb.cursors.DictCursor)
cursor.execute ("SELECT * FROM web_stat where
ID>"+str(self.lastid))
result_set = cursor.fetchall ()
for row in result_set:
last=row["ID"]b (this does not work why )
access.Edit()
access.Fields("customer").value= row["customer"]
t=row["time"]
print t
access.Fields("Time").value=t
access.Fields("phrase").value= row["phrase"]
access.Fields("key_word_phrase").value =
row["key_word_phrase"]
access.Fields("from_server").value = row["from_server"]
access.Fields("path_name").value = row["path_name"]
id = row["PageID"]
print id
g=str(id)
k=int(g)
access.Fields("PageID").value=k
access.Fields("server_name").value = row["server_name"]
access.Fields("file_name").value = row["file_name"]
access.Update()
temp.Edit()
temp.Fields("lastid").Value=k
temp.Update()
|
Extending Python with C: Cannot find MPI library
 (104 Views)
I am writing some Python code using the Message Passing Interface
(MPI), an API used in parallel computing. There exist a number of
Python implementations of MPI, but apparently they all rely on the
Numeric Python (numpy) package. I need to run my code on a particular
machine made available by my university, which does not have numpy and
will not be getting it.
So I am trying to write my own mini-wrapper for MPI in C to extend
my Python program.
There exists a special C compiler to use when compiling C programs
that use MPI, called mpicc.
Here is what I have tried:
I have written a minimal C program that uses MPI. It works correctly
when compiled with mpicc.
Then I've written Python boilerplate code and a Python script to
compile my C program into a Python-includable module. This does not
work a priori because the Python compilation script uses gcc rather
than mpicc. So I have taken the exact gcc command that the script uses
and replaced "gcc" with "mpicc".
This produces an *.so file that compiles without errors.
Unfortunately, it fails when I try to import it in Python. It can't
find the MPI library.
My MPI code looks like this (plus some boilerplate code):
/* Return the MPI rank of the current process. */
int rank(){
int argc;
char **argv;
int rank, size;
MPI_Init( &argc, &argv );
MPI_Comm_rank( MPI_COMM_WORLD, &rank );
MPI_Finalize();
return rank;
}
/* Main. A ' World' function. */
int hello() {
int rankNumber = rank();
printf (", World. I am process %d.\n", rankNumber);
return rankNumber;
}
My Python program that includes it looks like this:
import ctest
ctest.hello()
My error message is this:
[ore@localhost Opgave03]$ mpiexec -n 1 python ctest.py
Traceback (most recent call last):
File "ctest.py", line 1, in
import ctest
ImportError: /big/School/Cluster/Opgave03/ctest.so: undefined
symbol: ompi_mpi_comm_world
[ore@localhost Opgave03]$
Can anyone suggest anything Can I get MPI to work in Python
Last time I asked a similar question, someone recommended that I
check out Cython instead of C. Do MPI bindings for Cython exist
|
error using all()/numpy [TypeError: cannot perform reduce withflexible type]
 (178 Views)
all,
I'm pretty new to Python, but use it a lot lately. I'm getting a crazy
error trying to do operations on a string list after importing numpy.
Minimal example:
[start Python]
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a=['1','2','3']
>>> all(a)
True
>>> from numpy import *
>>> all(a)
Traceback (most recent call last):
File "", line 1, in
File "C:\Python25\lib\site-packages\numpy\core\fromnumeric.py", line
982, in all
return _wrapit(a, 'all', axis, out)
File "C:\Python25\lib\site-packages\numpy\core\fromnumeric.py", line
37, in _wrapit
result = getattr(asarray(obj),method)(*args, **kwds)
TypeError: cannot perform reduce with flexible type
[end of example]
It seems that Python calls numpy's "all" instead of the standard one,
is that right If so, how can I call the standard "all" after the
numpy import ["import numpy" is not a deable option, I use a lot
of math in my progs]
Is there another way around this error
Marc
|
Re: [Python-Dev] annoying dictionary problem, non-existing keys
 (124 Views)
bvidinli schrieb:
> I posted to so many lists because,
>
> this issue is related to all lists,
> this is an idea for python,
> this is related to development of python...
>
> why are you so much defensive
>
> i think ideas all important for development of python, software....
> i am sory anyway.... hope will be helpful.
You could take the answers from the people (including core developers)
as sign that it is *not* related to all lists.
Crossposting is generally frowned upon and should be avoided. If you
post here & people think that it is a python devel issue, they will
indicate that.
Diez
|
Cannot understand the detailedly the following code
 (138 Views)
At the url http://www.python.org/doc/essays/graphs.html there is some
code by Guido Van Rossum for computing paths through a graph - I have
pasted it below for reference -
Let's write a simple function to determine a path between two nodes.
It takes a graph and the start and end nodes as arguments. It will
return a list of nodes (including the start and end nodes) comprising
the path. When no path can be found, it returns None. The same node
will not occur more than once on the path returned (i.e. it won't
contain cycles). The algorithm uses an important technique called
backtracking: it tries each possibility in turn until it finds a
solution.
def find_path(graph, start, end, path=[]):
path = path + [start]
if start == end:
return path
if not graph.has_key(start):
return None
for node in graph[start]:
if node not in path:
newpath = find_path(graph, node, end, path)
if newpath: return newpath
return None
*** He then says------------------------
It is simple to change this function to return a list of all paths
(without cycles) instead of the first path it finds:
def find_all_paths(graph, start, end, path=[]):
path = path + [start]
if start == end:
return [path]
if not graph.has_key(start):
return []
paths = []
for node in graph[start]:
if node not in path:
newpaths = find_all_paths(graph, node, end, path)
for newpath in newpaths:
paths.append(newpath)
return paths
*** I couldn't understand how it was simple to change the function
find paths to find all paths. How would you think about writing this
second function recursively. Especially the part about if start==end:
return [path]. I feel you would give square brackets around path here
after first writing the inductive part ... for node in
graph[start] ....
and then by trial and error put square brackets around path in the
Basis part. Can someone please explain how to write this code.
|
Cannot build Python 2.4 SRPM on x64 platform
 (165 Views)
For those on several python lists, I appologize in advance for
cross-posting, but I'm really not sure which list is best to ask for
assistance with this.
Currently, I am trying to build the python2.4 SRPM from Python.org on a
RHEL4 x64 platform, but the build is failing with a very non-descript
error message.
.....
+ cd /var/tmp/python2.4-2.4-root/usr/bin
+ mv -f pydoc pydoc2.4
+ cd /var/tmp/python2.4-2.4-root/usr/bin
+ mv -f idle idle2.4
+ echo '#!/bin/bash'
+ echo 'exec /usr/bin/python2.4 /usr/lib64/python2.4/idlelib/idle.py'
+ chmod 755 /var/tmp/python2.4-2.4-root/usr/bin/idle2.4
+ cp -a Tools /var/tmp/python2.4-2.4-root/usr/lib64/python2.4
+ rm -f mainpkg.files
+ find /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/lib-dynload -type f
+ sed 's|^/var/tmp/python2.4-2.4-root|/|'
+ grep -v -e '_tkinter.so$'
error: Bad exit status from /var/tmp/rpm-tmp.55639 (%install)
RPM build errors:
user jafo does not exist - using root
group jafo does not exist - using root
user jafo does not exist - using root
group jafo does not exist - using root
Bad exit status from /var/tmp/rpm-tmp.55639 (%install)
If I try to run /var/tmp/rpm-tmp.55639 manually from the prompt manually
after the rpmbuild fails, it runs properly to completion. If I try to
comment out that last line (find
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/lib-dynload -type f | sed
's|^/var/tmp/python2.4-2.4-root|/|' | grep -v -e '_tkinter.so$' ) that seems
to be causing the script to fail, rpmbuild finishes, but with several error
msgs, complaining about missing files in the lib64 directories:
+ rm -f /tmp/python-rpm-files.4859
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/brp-strip
+ /usr/lib/rpm/brp-strip-static-archive
+ /usr/lib/rpm/brp-strip-comment-note
Processing files: python2.4-2.4-1pydotorg
error: File not found by glob:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/*.txt
error: File not found by glob:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/*.py*
error: File not found:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/pdb.doc
error: File not found:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/profile.doc
error: File not found:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/curses
error: File not found:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/distutils
error: File not found:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/encodings
error: File not found:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/plat-linux2
error: File not found:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/site-packages
error: File not found: /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/test
error: File not found: /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/xml
error: File not found: /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/email
error: File not found:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/compiler
error: File not found: /var/tmp/python2.4-2.4-root/usr/lib64/python2.4/bsddb
error: File not found:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/hotshot
error: File not found:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/logging
error: File not found:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/lib-old
Executing(%doc): /bin/sh -e /var/tmp/rpm-tmp.95118
+ umask 022
+ cd /usr/src/redhat/BUILD
+ cd Python-2.4
+ DOCDIR=/var/tmp/python2.4-2.4-root/usr/share/doc/python2.4-2.4
+ export DOCDIR
+ rm -rf /var/tmp/python2.4-2.4-root/usr/share/doc/python2.4-2.4
+ /bin/mkdir -p /var/tmp/python2.4-2.4-root/usr/share/doc/python2.4-2.4
+ cp -pr Misc/README Misc/cheatsheet Misc/Porting
/var/tmp/python2.4-2.4-root/usr/share/doc/python2.4-2.4
+ cp -pr LICENSE Misc/ACKS Misc/HISTORY Misc/NEWS
/var/tmp/python2.4-2.4-root/usr/share/doc/python2.4-2.4
+ exit 0
Processing files: python2.4-devel-2.4-1pydotorg
error: File not found:
/var/tmp/python2.4-2.4-root/usr/lib64/python2.4/config
Processing files: python2.4-tools-2.4-1pydotorg
Requires(rpmlib): rpmlib(CompressedFileNames)
|
ftplib question (cannot open data connection)
 (148 Views)
Hi ,
I'm using a simple program that uploads a file on a remote ftp server.
This is an example (not the whole program):
def store(self,hostname,username,password,destdir,srcpath):
self.ftp = ftplib.FTP(hostname)
self.ftp.login(username,password)
self.ftp.set_pasv(False)
self.ftp.cwd(destdir)
fobj = file(srcpath,"rb")
destname = os.path.split(srcpath)[1]
self.ftp.storbinary("STOR "+destname,fobj)
The ftp server cannot use passive connections, and I can do nothing
about that. Here is the problem: I can connect to this ftp server from
my home computer, which is behind a NAT firewall. I can also connect to
it from another computer, but I'm not able to upload any file. I tried
to debug with a simple "ftp -v -d" command line program and apparently
the problem is with the "EPRT" command:
ftp> ls
---> EPRT |1|195.228.74.135|55749|
200 Port command successful.
---> LIST
425 Cannot open data connection.
ftp>
Well, the port number given by EPRT is bad - it is a closed port on this
computer. I can open a small port range for this, but I would not like
to open all ports and disable the firewall completely.
Here are my questions:
1. How can I instruct ftplib to use specific ports for incoming
connections (For example, ports between 55000 and 56000).
2. How it is possible that the same program works from another computer
that is behind a NAT firewall
|
C/C++ on UNIX Developer required in Woodmead, Johannesburg
 (128 Views)
We seek the following sort of experience / skill for developer
resources (if u do not qualify - we offer a handsome referral fee if
you refer someone that is succesfully placed:-) .
C Programming 5 years
C++ Programming 2 years
SQL Programming 2 years
Software Design 2 years
Software Engineering Process 3 years
GUI Development 1 year
Unix/Linux environment 2 years
Scientific/Mathematical Programming 2 years
These skills all need to be current.
The candidate should demonstrate an ability to work resourcefully and
independently, whilst delivering in the framework of a team. The
candidate must also demonstrate a willingness and dee to program
hands-on in C and C++ code. He/she must have personally developed
significant amounts of program code, demonstrating and requiring
modular design and the use of a source code repository for version
control.
The candidate must communicate well, and be comfortable discussing
design issues with both the team and the customer. His / her present
role should require this of him/her.
The candidate must be able to describe the software development
lifecycle and identify his/her personal points of interaction in that
cycle. These points must be Functional Requirements Specification,
Software Design, Programming and Unit Testing.
The following skills would be an advantage:
Object oriented design
UML and the use of design tools like Rational Rose
Development tools (GDB, DBX, WxWidets/Qt/GTK, Makefiles
etc.)
|
Re: PyQt, Cannot send events to objects owned by a different thread?
 (205 Views)
On Sun Nov 25 15:22:24 CET 2007, Alexander Tuchacek wrote:
> i try to adress an qt object
>
> self.statusbar.showMessage("rtt %s...." % (n.rtt))
>
> in an callback function, comming from a shared lib importet by ctypes, on
> osx this works wonderfull
>
> when i run the same code on linux (ubuntu gutsy), i get this core dump, ok,
> i understand that the problem is, that i cant speak to the qt thread, but
> why does it work on osx
Maybe the implementation of the library is different on OS X. You need to
give us more enough information to work with.
> shall i recompile python pyqt or sip without threads
>
> could somebody give me a hint what to do best how can i call a qt object in
> an c-lib callback
You can either construct some sort of event handling mechanism or use signals
and slots. Personally, I'd use signals and slots for this, if possible.
The idea would be to set up a connection between your callback code and
the status bar's showMessage() slot. Then you would only have to emit that
signal to update the status bar.
David
|
urllib: cannot open webpage which requires authentication
 (179 Views)
I tried using urllib.urlopen to open a personalized webpage
(my.yahoo.com) but it doesn't work:
print urllib.urlopen(http://my.yahoo.com).read()
Instead of returning my.yahoo.com, it returns a page asking me to log
in.
So then I tried urllib.urlencode:
data = urllib.urlencode({'action': 'https://login.yahoo.com/config/
login', 'login': , 'passwd': })
print urllib.urlopen(http://my.yahoo.com, data).read()
However, this doesn't work either. Is there a way to do this
|
Cannot formulate regex
 (130 Views)
I'd like to filter spam from a certain company. Here are examples of
strings found in their spam:
Mega Dik
Mega D1k
MegaDik
Mega. Dik
M eg ad ik
M E _G_A_D_ IK
M_E_G. ADI. K
I figured that this regex would match all but the second example, yet
it matches none:
|[^a-z]m[^a-z]e[^a-z]g[^a-z]a[^a-z]d[^a-z]i[^a-z]k[^a-z]|i
What would be the regex that matches "megadik" regardless of whatever
characters are sprinkled throughout
|
cannot create my own dict
 (148 Views)
all,
This morning I tried to create my own read-only dictionary, and failed
miserably.
I don't understand why, can somebody enlighten me
Below is a brute-force experiment that cannot deal with "x in obj", plz read
the explanation below the code:
--------------------------------
class myowndict(object):
def __init__(self, mydict):
self.mydict = mydict
# Below is produced with
# print '\n'.join([' self.%s = self.mydict.%s' % (v,v)
# for v in dir(dict)])
# commented-out functions done by hand
#
#self.__class__ = self.mydict.__class__
self.__cmp__ = self.mydict.__cmp__
self.__contains__ = self.mydict.__contains__
self.__delattr__ = self.mydict.__delattr__
self.__delitem__ = self.mydict.__delitem__
#self.__doc__ = self.mydict.__doc__
self.__eq__ = self.mydict.__eq__
self.__ge__ = self.mydict.__ge__
self.__getattribute__ = self.mydict.__getattribute__
self.__getitem__ = self.mydict.__getitem__
self.__gt__ = self.mydict.__gt__
self.__hash__ = self.mydict.__hash__
#self.__init__ = self.mydict.__init__
self.__iter__ = self.mydict.__iter__
self.__le__ = self.mydict.__le__
self.__len__ = self.mydict.__len__
self.__lt__ = self.mydict.__lt__
self.__ne__ = self.mydict.__ne__
#self.__new__ = self.mydict.__new__
self.__reduce__ = self.mydict.__reduce__
self.__reduce_ex__ = self.mydict.__reduce_ex__
self.__repr__ = self.mydict.__repr__
self.__setattr__ = self.mydict.__setattr__
self.__setitem__ = self.mydict.__setitem__
self.__str__ = self.mydict.__str__
self.clear = self.mydict.clear
self.copy = self.mydict.copy
self.fromkeys = self.mydict.fromkeys
self.get = self.mydict.get
self.has_key = self.mydict.has_key
self.items = self.mydict.items
self.iteritems = self.mydict.iteritems
self.iterkeys = self.mydict.iterkeys
self.itervalues = self.mydict.itervalues
self.keys = self.mydict.keys
self.pop = self.mydict.pop
self.popitem = self.mydict.popitem
self.setdefault = self.mydict.setdefault
self.update = self.mydict.update
self.values = self.mydict.values
# end of __init__
if __name__ == '__main__':
fd = myowndict({1:10})
print 1 in fd # FAILS! (with "TypeError: iterable argument required")
--------------------------------
I wanted to make my own dictionary. However, a simple element test failed
(after implementing various __*__ functions), and I cannot figure out why.
The above code is a brute force attempt, where I forward all methods (except
__class__, __doc__, __init__, and __new__) to my local 'mydict' object.
IT STILL FAILS.
So if copying all methods of a native dictionary is not enough, what should I
do to make my class work as a dictionary WITHOUT deriving from dict (which will
obviously work).
Sincerely,
Albert
|
Py3K: Ensuring future compatibility between function annotation basedtools
 (135 Views)
There could be future compatibility issues between libraries using the new
function annotation scheme: PEP 3107 -- Function Annotations
See also: http://www.python.org/dev/peps/pep-3107/
Let's assume two hypotetic libraries:
mashaller: provides JSON marshalling support
typechecker: provides runtime type checking
Let's write a simple function that uses both libraries:
from marshaller import marshall, JSON
from typechecker import check, Str
@marshall
@check
def splitter(s:Str) -> JSON:
return s.split(',')
The function get a singe string and returns JSON encoded list of it's comma
separated parts. Both libraries can be used together without problems as long
as all arguments and the return value are annotated by at most one annotator
object. However, there could be frequent use cases, when multiple annotations
for a single argument or return value is required:
@marshall
@check
def splitter(sJSON, Str)) -> JSON:
return s.split(',')
The above function does the same as the first one, but accepts a JSON encoded
string. This solution works only if both libraries can cooperatively handle
composite annotator objects and do not complain about unknown ones.
(Note, that the order of processing depends on the order of the decorators,
not on the order of the annotators.)
Let me suggest the following recommendation for tool developers:
If you encounter a tuple as the annotator, then iterate it and process only
the known ones while silently skipping all others. Keep all existing
annotators if you include new ones. Create a tuple if you find an existing
annotator and need to include a second one. Extend existing tuples by
replacing them with new ones including new annotator(s).
(Possibly lists or dictionaries in place of tuples I don't think so. Ideas)
This way all annotation based tools will be compatible and should work
seamlessly without imposing any unnecessary constraint.
Anybody with a better solution Any comments
Greetings, Viktor
|
ann: Python at the IET
 (131 Views)
If you're in London around 6.30pm this Thursday evening, July 5th 2007, you might want to drop in on The Institution of
Engineering and Technology [1] on the Embankment near Waterloo Bridge [2] for "A Light byte of Python" [3]. Michael
Grazebrook, Pete Ryland and I are flying the Python flag for the benefit of technologists who have not yet had the
pleasure. Michael will be using ctypes to control a USB-interfaced sensor kit; Pete will be demoing user interfaces;
I'll be using BeautifulSoup and sqlite3 to populate a database from a web page and (time permitting) using csv and
ReportLab to push it back out again.
We're presenting the thing as a bring-a-laptop workshop, and it would be great if we had experienced Pythoneers along to
help afterwards (in addition to ourselves). The take-up's been quite high for the event and there's tea & coffee
beforehand and sandwiches afterwards.
Tim Golden
[1] http://www.theiet.org/
[2] http://www.iee.org/OnComms/Branches/...nues/savoy.cfm
[3] http://www.iee.org/OnComms/Branches/...vents/july.cfm
|
contextlib.closing annoyance
 (117 Views)
it looks like contextlib.closing fails to be idempotent,
i.e. wrapping closing() around another closing() doesn't work.
This is annoying because the idea of closing() is to let you
use legacy file-like objects as targets of the "with" statement,
e.g.
with closing(gzip.open(filename)) as zf: ...
but what happens if the gzip library gets updated the dumb way to
support the enter and exit methods so you don't need the explicit
closing call any more The dumb way of course is to just call
closing() inside the library. It seems to me that
closing(closing(f)) ought to do the same thing as closing(f).
Let me know if I'm overlooking something. I'm thinking of submitting
an RFE.
|
"assert" annoyance
 (119 Views)
So I have some assert statements in my code to verify the absence of
some "impossible" conditions. They were useful in debugging and of
course I left them in place for "real" runs of the program. Umpteen
hours into a run, an assertion failed, and of course since failure
was "impossible", I didn't catch the exception so the whole program
crashed. I don't know what I'd have done with the exception anyway,
since it would have had to be caught at an outer scope where the
data I cared about was no longer around, or else I'd have had to
predict in advance what I needed to examine and pass that as a
an arg to the assert statement.
What I really want is for any assertion failure, anywhere in the
program, to trap to the debugger WITHOUT blowing out of the scope
where the failure happened, so I can examine the local frame. That
just seems natural, but I don't see an obvious way to do it. Am I
missing something I guess I could replace all the assertions with
function calls that launch pdb, but why bother having an assert
statement , Paul Rubin writes:
> So I have some assert statements in my code to verify the absence of
> some "impossible" conditions. They were useful in debugging and of
> course I left them in place for "real" runs of the program. Umpteen
> hours into a run, an assertion failed, and of course since failure
> was "impossible", I didn't catch the exception so the whole program
> crashed.
This is exactly the sort of check which is best done as unit
tests. The program has no 'assert' cruft in it, and the tests can be
as comprehensive as needed without having any impact on the actual
running program.
--
\ Legionnaire: "We have their leader captive!" Cr: "Is he |
`\ bound" Legionnaire: "Of his health I know not, ." -- The |
_o__) Goon Show, _The Histories Of Pliny The Elder_ |
Ben Finney
|
Re: string formatter %x and a class instance with __int__ cannothandle long
 (138 Views)
En Thu, 21 Jun 2007 05:36:42 -0300, Kenji Noguchi
escribi:
> I confirmed that "%08x" % int(y) works. And yes, I'm hoping so.
> It actually works that way if the v is less than or equal to 0x7ffffffff.
>
>> It is a bug, at least for me, and I have half of a patch addressing it.
>> As a workaround, convert explicitely to long before formatting.
>
> I'm interested in your patch. What's the other half still missing
As you have seen, PyString_Format doesn't handle well objects that can be
converted to long but are not longs themselves; I've modified that
function, but PyUnicode_Format has a similar problem, that's "the other
half".
Maybe this weekend I'll clean those things and submit the patch.
--
Gabriel Genellina
|
|