Ben Finney benfinney.id.au> writes:
> > (1) assertRaises REALLY needs a better error message. If not a custom
> > message, at least it should show the result it got instead of an
> > exception.
>
> +1
>
> Is this one of the many improvements in Python 3.2's ‘unittest’ that
> Michael Foord presid
roblems of the new io package),
I think the only reason not to move to python3 will be any
dependency one might have on 3rd party packages that haven't
themselves made the switch yet. Of course, that will be a big
issue for some time to come for many people.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
sort of mechanism for a site
to say "I'm not claiming anything about my identity, I'm just
providing you an https channel over which to talk to me
securely".
I fault the designers of https for this oversight.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
.timeit('for res in myset: break', 'myset=range(100)')
> 0.3293300797699
>
> I'd never expect that for-loop assignment is even faster than a
> precreated iter object (the second test)... but I don't think this
> for-looping variable leaking behavior is guaranteed, isn't it?
My guess would be that what's controlling the timing here is
name lookup. Three in the first example, two in the second,
and one in the third.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
d information. I found this
one, which is a nice summary but doesn't give examples:
http://www.network-theory.co.uk/docs/pytut/PythonScopesandNameSpaces.html
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
same object that was just mutated. Unlike
the '+' case where 'a' is bound to a newly created list object.
Personally I think += and kin were a bad idea and should have been
removed in Python 3.0 :) Even though I occasionally use them. (Maybe
I'll stop.)
> A
laid out in full, with all the consequences it would
entail examined.
> I think this situation should be handled in documentation. (I'm a tech writer
> in my day job ... oh wait, I forgot ... I got laid off from my day job in
> December.) I'll look into what the standard Python doc set says on this
> matter.
Doc patches are always welcome, and from what I hear easier to get
accepted than code patches ;)
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
n the other hand, it is one of the, well,
bugs, that is avoided by the 'format' method in 3.x.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
o.x
> 1000
>
> I notice that the first example's instance doesn't have a __dict__.
> Is the second way the idiom?
The lack of a __dict__ is why you can't set the attribute.
I've occasionally wanted to use instances of object as holders of
arbitrar
to work with binary byte
streams, you want to use the 'bytes' type. Bytes contstants are
written with a leading 'b', so the code snipped above would become
self.out.write(b'BM')
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
str converted over to binary bytes to
> write to bmp file.
(I reformatted your message slightly to make the code block stand out more.)
A byte array is an array of bytes, and it understands integers as input.
Check out the PEP (the official docs leave some things out):
http://www.p
open("temp3.html", "wb") as fd:
... fd.write(f)
The "b''" is the stringified representation of a bytes object,
which is what urllib.request returns in python3. Note the 'wb',
which is a critical difference from the python2.6 case. If y
Saurabh wrote:
> > This isn't exactly how things work. The server *sends* you bytes. It can
> > send you a lot at once. To some extent you can control how much it sends
> > before it waits for you to catch up, but you don't have anywhere near
> > byte-level control (you might have something lik
with 46229 bytes ? Or is it something else ?
>
> That's just a bug in urllib in Python 3.0.
What makes you say that's a bug? Did I miss something? (Which is entirely
possible!)
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
mattia wrote:
> Il Tue, 17 Mar 2009 10:55:21 +0000, R. David Murray ha scritto:
>
> > mattia wrote:
> >> Hi all, can you tell me why the module urllib.request (py3) add extra
> >> characters (b'fef\r\n and \r\n0\r\n\r\n') in a simple example like the
>
inmutable+1; inmutable*=unused; del unused"
>
> There seems to be no really simple expression for the above extensions,
> and I take that as an indication
> that the proposed feature could be quite useful.
For the first one, we have:
lst[:0] = [5, 6]
And unless I'm misun
still think that the cost of a new keyword is probably too high a
> price to pay, but I like the idea.
Yeah, you have to make a really, _really_ compelling case to get
a new keyword added. Something you can't do any other way, or at
least not without an awful lot of hassle.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
Arg, my apologies, I posted my replies to the wrong group :(
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
Jean-Paul Calderone wrote:
> On Tue, 17 Mar 2009 15:17:56 + (UTC), "R. David Murray"
> wrote:
> >Jean-Paul Calderone wrote:
> >> On Tue, 17 Mar 2009 12:15:23 +0530, Saurabh wrote:
> >> >> This isn't exactly how things work. The server *
I love the new sentinel argument for the next function in python3!)
>
> next() doesn't have a sentinel argument. It's iter() which does, and that's in
> 2.x also.
But it does have a 'default' argument, and you can pass that
a sentinel, so it amounts to the same thing ;)
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
mmer type, eg:
@GET
def foo(self): pass
@POST
def foo(self): pass
have them type:
def GET_foo(self): pass
def POST_foo(self): pass
It's even one less character of typing (the :)
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
.
>
> Nontheless, a warning would be helpful, possibly with some doc.
Submitting an issue to the tracker with this request would probably be a
good idea. Even better if you include a suggested patch.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
except StopIteration: break
but the version using SENTINEL avoids having the interpreter do the work
of generating a traceback, and is IMO slightly prettier.
I'm sure there are other use cases, too, but probably not a huge number
of them. Certainly not as many as using the parameter as a default.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
any way that is really satisfying.
Someone else suggested the property model, though that is probably not
as elegant as you want either.
Sohow about the below. Extending it to handle multiple classes is
left as an exercise for the reader :) As is extending it to handle
stacking the
ementation detail.
What use case do you have for wanting to disable it?
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
nk it was GTK
bindings, even though you were dealing with just network IO. But I don't
remember clearly and did not record the reference. Perhaps the person
who posted that info will answer you, or you will be able to figure out
from these clues. Unfortunately I'm not 100% sure it was Webkit
zero__')
> > def __bool__(self):
> >
> > and even better(?) if it could depend on python version!
> >
> > or maybe there's another solution to the __bool__ problem above? (there's
> > also next methods, can't think of anything else
all the comma would normally be an argument
separator, so in that context you do need the parenthesis as well:
test_func(val=('val1',))
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
iteration with equality if
it doesn't). But the _intent_ of __contains__ is that comparison be
by equality, not object identity, so if the two are not the same something
weird is going on and there'd better be a good reason for it :)
In summary, 'in' is the thing to use
ook up the capitalized version of the string (eg: 'One')
in the __init__.py module's global namespace, thus picking up the
class, and then calls it to create an instance, which is then
returned.
Then your code that uses this can do:
from parser import parserFactory
myparser
\n")
> data = self.snap.read(length)
> self.snap.close()
> break
>
> the output data is supposed to read the whole fie but it only reads a
> part of it. Why is it encountering an early EOF ?
It's not. In the second case you told it to read only 4096 bytes. You
might want to read the docs for the 'read' method, paying particular
attention to the optional argument and its meaning.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
n they are called,
__init__'s namespace is in whatever state it was left in when __init__
ended. In this case, that means that 'option' is pointing to the value
it had at the _end_ of the for loop.
Hope this helps. I find that thinking in terms of namespaces helps
me understand how Python works better than any other mental model
I've come across.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
n)
> else:
> print("The compiled pattern is stored.")
FYI this is almost exactly the approach the re module takes to
caching the expressions. (The difference is re adds a type
token to the front of the key.)
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 20 Mar 2009 at 07:09, Sreejith K wrote:
On Mar 20, 4:43?pm, "R. David Murray" wrote:
Sreejith K wrote:
Hi,
snapdir = './mango.txt_snaps'
snap_cnt = 1
block = 0
import os
os.chdir('/mnt/gfs_local')
snap = open(snapdir + '/snap%s/%s' % (rep
7;t read the whole
file? You didn't log it.
Both your statements might be true, but until you show the logging
output proving it, you don't _know_ that your assumptions are true.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
k back further at the post which
they were commenting on. Those two lines do not constitute
consecutive lines of code, they are individual replacements
for individual lines in two different previous examples, one
of which updates the dict in place and the other of which
creates a new dict.
I thin
badly indeed if your handouts
> and computers don't make the same assumptions!
Print as function can be used in 2.6+ via 'from __future__ import
print_function'.
So it is probably best to teach print-as-function regardless.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
works in python (PYTHONPATH, sys.path) so that you can decide
which of the many possible ways to make this work will serve you
best.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
lmost out the door and
that fixes the I/O performance issue.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
you want next(g) to yield 3, you'd have to do something like:
g = (x for x in s[:])
where s[:] makes a copy of s that is then iterated over.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
cases I _do_ have to support a number
of servers that are still running 2.5 :(
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
tion that would yield such an open function that
otherwise is identical to the default open.
What's the standard python idiom for when consumer code should be
able to specialize the classes used to create objects returned from
a called package? (I'm tempted to say monkey patching the module,
but that can't be optimal :)
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
names point to in
its local and global namespaces, but cannot modify what names point to
in the closure namespace.
Of course, we can produce the same _effect_ as a computer science closure
in Python by using mutable objects...which is exactly parallel to the
difference between passing mutable or immutable objects in a function
call.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
"Gabriel Genellina" wrote:
> En Sun, 22 Mar 2009 15:11:37 -0300, R. David Murray
> escribió:
> > "Gabriel Genellina" wrote:
> >> En Sat, 21 Mar 2009 23:58:07 -0300, escribió:
> >> >
> >> > class file(io.TextIOWrapper):
> &
and myglobal2 are not imported into
> python's interactive namespace. i'd like them too -- how can i do
> this?
>
> (note my file does not contain a __name__ == '__main__' clause.)
I'm not familiar with IPython, but perhaps 'from myfile import *
mattia wrote:
> Il Sun, 22 Mar 2009 16:52:02 +0000, R. David Murray ha scritto:
>
> > mattia wrote:
> >> Can you explain me this behaviour:
> >>
> >> >>> s = [1,2,3,4,5]
> >> >>> g = (x for x in s)
> >> >>> ne
is that I'm writing a turbogears application in which the
> URLs are determined by the method names. People might want to change
> these names if they want to change the URLs. One way would be to put
> the method names into a turbogears configuration file and the @rename
> decorator could fetch it from there.
Use a WSGI routing engine instead.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
' to read the 'file' exposed
by fuse. Correct?
So you still have not decoupled the python read from the fuse read in
your debugging. You are focused on the fact that the python read "must
be failing", yet you still (as far as you have told us) not _proven_
that by logging
losure is a "read-only closure".
But now with Python 3.x we can really have fun (thank you for that info):
>>> def g():
... def a(x):
... nonlocal z
... z = z + x
... def b(x):
... nonlocal z
... z = z - x
... def p()
impler statement works, too:
>
>g = iter(s[:])
Yes, but one presumes that in the real code that prompted the OP's
question he wasn't just returning 'x'.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
the 'snap.read(length)' call is not returning the whole
file is based on the fact that less is only showing him part of the file.
There are several steps between that 'snap.read' and less displaying on
the terminal whatever bytes it got back from its read call in whatever
way it is less chooses to display them
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
mete wrote:
> Hi all,
> I got a problem. İ want to send udp package and get this package (server and
> clinet ). it's easy to python but i want to look the udp header how can i
> do ?
The English word is 'packet'.
If you are on Linux you can use raw sockets fo
e will be closed at program termination anyway,
but is a good habit to get in to.)
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
> Any idea why alternate path is not working?
Possibly because the package gets installed into ~/lib/python, but
you haven't put that directory onto the PYTHONPATH.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
' or hexdump instead of less to read the file?
Run experiments until you gather enough clues to make a guess as to what
is going on, then test your theory. Repeat until success :)
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
e, and you've told us that you have '50 modules' with a lot
of shared code that 'could be used across other projects', perhaps you
see why relative imports are generally discouraged. If you use only
relative imports, the code _can't_ be shared across multiple p
and handling of .pth files.
As for best practice, I would say whichever one meets your needs.
The PEP is addressing the needs of users who do not have root privs but
who want to install packages via distutils in such a way that they will
act as if they had been installed in the system site-packag
)])
Modify as appropriate to your actual needs.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
ggestion)
I would be greatful. (This has to be stdlib only, by the way, I
can't introduce any new modules into the application so pyparsing is
not an option.)
The challenge is to turn a string like this:
a=1,b="0234,)#($)@", k="7"
into this:
[("a", &quo
> for m in r.finditer(s)
> ]
>
> Things like internal quoting ('b="123\"456", c="123""456"') would
> require a slightly smarter parser.
Thank you thank you. I owe you a dinner if we are ever in the
same town (are you at Pycon
John Machin wrote:
> On Mar 27, 6:51 am, "R. David Murray" wrote:
> > OK, I've got a little problem that I'd like to ask the assembled minds
> > for help with. I can write code to parse this, but I'm thinking it may
> > be possible to do it with
Paul McGuire wrote:
> On Mar 26, 2:51 pm, "R. David Murray" wrote:
> > OK, I've got a little problem that I'd like to ask the assembled minds
> > for help with. I can write code to parse this, but I'm thinking it may
> > be possible to do it with
does the
right thing:
def Bfoo_func(self):
self.B.foo_func(self)
Or maybe you could look at generic methods, which provide a way
to do multiple dispatch.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
7;invalid data'
> start = 10
>
>
> Please tell me how to solve this problem.
That doesn't look anything like a python traceback. I'm guessing
you are using some sort of web framework? Perhaps you should
try asking in the forum for the framework.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
e subprocess.Popen instead, that's better).
By the way, when you get closer to getting the above to work, you're
going to want to add a '\n' to the end of that string you are writing.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
Tk
[...]
> Anybody has a quick fix?
Yep. Run 'make test' instead of running them one by one. make test
will run them under regrtest, which has mechanisms for detecting tests
that are expected to or may reasonably fail on a given platform. Then if
you still have errors, report back
the Skip messages (and any real errors) from the
make test run? I can run through them quickly for you then, and
then we can focus on the ones that are the real errors.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
right?
> maybe my connection to the server is timing out during the upload?
> web server is IIS 6.0.
> python is 2.5.2.
> IIS webmapping does not use "-u" b/c nothing works when that option is
> used.
What are you using to do the upload? What error message do you g
-contiguous ranges of integers for a
> particular column if a string occurs ("by accident" perhaps) in more than
> one.
>
> 2 - don't bother with isNumeric. just return the cast value or catch the
> exception:
>
> [...]
> try:
> dimensions.append(flo
On Tue, 7 Apr 2009 at 09:01, andrew cooke wrote:
R. David Murray wrote:
[...]
try:
dimensions.append(float(s))
except:
dimensions.append(float(quantization[s]))
No, no, no; never use a bare except! :)
can you explain why? i can't think of any reason why the code wou
pected. I know there have been quite
> a few changes to the subprocess module between Python 2.5 & 2.6 so
> maybe you need to upgrade. (Failing that, we'd have to work a bit
> harder to pin down a specific bug in the 2.5 code since 2.5 is now
> in bugfix-release mode only, I think).
2.5 is in security-fix-only mode.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
pep277 test_py3kwarn test_scriptpackages
> test_socketserver test_sqlite test_startfile test_sunaudiodev
> test_tcl test_timeout test_unicode_file test_urllib2net
> test_urllibnet test_winreg test_winsound test_zipfile64
These as it implies are all normal.
> 3 skips unexpected on linux2:
> test_tcl test_dbm test_multiprocessing
And these we've covered.
So your biggest barrier to getting your python working for your
purposes is getting python to find the libtk8.5.so. Everything
else you can ignore, unless you want to try to track them down.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
r
of interesting hits.
I also remember seeing at least one package announced on
python-announce that referred to genetic algorithms,
so you might check the archives of that mailing list
as well.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
em (and that means that the test is a little fragile). If you
rerun that test in verbose mode without the pipe into tee, does it pass?
> The output for individual test_httpservers was posted here:
> http://mail.python.org/pipermail/python-list/2009-April/708041.html
Hmm. These puzzle me.
.
>
> Everything is done as root.
I got failures (different failures) when I tried running that test as
root. You might try running it as a regular user, both before
and after the install.
> I'll move on with make install.
>
> Thanks for your help; I'm progressing :-)
's all e-mail to them. Granted the scourge of abbreviated words
> and lol-speak is just as bad there. Sigh.
lol-speak originated on IRC. (Or probably even earlier on the original
bitnet relay chat.)
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
Murali kumar wrote:
> hi all..
>
>
> please see my attached document..
I think you'll get more help if you post in plain text.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
I've tried some escape chars but it doesnt seems to work.
>
> Does anybody has the escape char sequence I should be using or a work around
> for this? Thanks in advanced for your replies.
As far as I can tell what you are getting is invalid XML.
So I think the answer is &q
at the shell
> (as oppose lookup at Python Doc). Can I somehow link the actual Python
> source code to iPython so that it can be accessed in that way?
Notice that the filetype is '.so'. That means it is a compiled
C module, so there is no python source to view.
--
R. David Murray
the $varname format you used above).
Which you choose depends on how you want to work, but I'd recommend
.format() for most things.
Except for your os.system call, where I'd recommend using the subprocess
module instead, in which case you'd do something like this:
call(['sixa', 'action', 'profile', profile])
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
m not going to claim
that this is the best code that could be written for this task :)
Oh, and there's more involved in actually printing the headers if you
need to deal with non-ASCII characters ("encoded words") in the headers.
(That's in the docs for the email module, though it
pose module C imports module B as well?
So, no, not in any useful way.
--
R. David Murray http://www.bitdance.com
--
http://mail.python.org/mailman/listinfo/python-list
a variable with the module name (excluding the .py), you can't
> use 'import' as it is. Instead, use the __import__ functio (I wonder if
> there is anything more elegant) which returns the plugin.
In 2.7 and 3.1 there will be:
from importlib import import_module
myna
Gary Herron wrote:
> MRAB wrote:
> > Grant Edwards wrote:
> >> On 2009-05-21, Christian Heimes wrote:
> >>> seanm...@gmail.com schrieb:
> The explaination in my introductory Python book is not very
> satisfying, and I am hoping someone can explain the following to me:
>
> >>> 4
On Mon, 17 Jan 2011 08:33:42 +, Mark Summerfield
wrote:
> from ..Graphics import Xpm
> SVG = 1
>
> I can do the relative import with Python 3.0 and 3.1 but not with
> 3.2rc1:
What about 3.1.3? I wonder if it is related to this issue:
http://bugs.python.org/issue79
ding to do.
--
R. David Murray http://www.bitdance.com
IT ConsultingSystem AdministrationPython Programming
--
http://mail.python.org/mailman/listinfo/python-list
John Machin wrote:
> On Jun 8, 12:13 am, "R. David Murray" wrote:
> > higer wrote:
> > > My file contains such strings :
> > > \xe6\x97\xa5\xe6\x9c\x9f\xef\xbc\x9a
> >
> > If those bytes are what is in the file (and it sounds like they ar
of Code project to create a 3to2 processor.
That would let you maintain the code in 3.x, and have it automatically
translated on demand so that it will run under 2.x (where x goes back
to at least 5, I think, but I'm not sure).
Of course, it isn't finished yet, so it won't do you any
a simple thing as ssh to my localhost.?
I would suggest using the 'setlog' method of child to get
more debugging information from pexpect. I've found that the
best way to diagnose the source of a timeout.
--
R. David Murray http://www.bitdance.com
IT Consultin
; I'm going to go back and re-read PEP 8 and see if I perhaps don't
> recall the right guidelines since no one else here seems to have had
> the same observation.
Well, I for one looked at that long pylint output when I first tried it,
and switched to another tool :)
(pyflake
your description, I don't see any reason to prefer any alternate
data structure. 1000 small CSV files should fit in a modern computer's
memory with no problem...and if it does become an issue, worry about it
then.
One thought, though: you might want to create a list subclass to hold
y
Chris Rebert wrote:
> On Thu, Jun 11, 2009 at 1:41 PM, Stef Mientki wrote:
> > Peter Otten wrote:
> >> Stef Mientki wrote:
> >>> Peter Otten wrote:
> Stef Mientki wrote:
> > I packed all sources with zipfile,
> > but the compression doesn't seem to be very good.
> >
>
>
92 matches
Mail list logo