Hi,
I'm new to python. Given a class, how can I get know what
attributes/functins in it without dig into the source?
-
narke
--
http://mail.python.org/mailman/listinfo/python-list
Thank you Hans. Could you give me a simple sample of using inspect?
--
http://mail.python.org/mailman/listinfo/python-list
Thank you All !
--
http://mail.python.org/mailman/listinfo/python-list
When I specify an source encoding such as:
# -*- coding: GBK -*-
or
# -*- coding: GB2312 -*-
as the first line of source, I got the following error:
SyntaxError: 'unknown encoding: GBK'
Does this mean Python does not support GBK/GB2312? What do I do?
-
narke
--
http://mail.python.org/mailm
Thank you All ! I am going to update ...
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
Anyone was using pmock for unit testing with python? I met a problem
and hope someone to help me. For short, the pmock seems can not mock a
iterator object.
For example, the tested object is foo, who need to send message to
another object bar. So, to test the foo, I need mock a mockBar. B
> def mockit(): raise StopIteration
> now pass mockit()
but it behaviors differenctly when pass in a mockit() and pass in an
iterator with empty. so i think the code emulates nothing.
> def intit(k):
> for i in range(k): yield i
Now you mean define my own iteration without the help of pmock.
Peter,
for a object foo who need a iterator to do a job, i write test to make
sure the foo correctlly used the iterator, so a simple empty iterator
is not enough. because in the case, i need to see if or not the foo
called the iterator to get the proper data from it and do the proper
translating
I'v just completed a small python project, which includes a main py
file and a couple of classes in seperated py files. I can run it under
the development directory, but how to distribute them? Is there any
good practice here?
Thanks in advance.
-
narke
--
http://mail.python.org/mailman/listi
Peter,
I'm so sorry, the letter was originally wrote to Terry, not to you!
I guess Terry not very familar to unit testing because he said:
-- cut --
I am not familiar with pmock, but my impression is that mock objects
are
for objects that you may not have available, such as a connection to a
data
Thank You All
--
http://mail.python.org/mailman/listinfo/python-list
#x27;,
author="Steven Woody",
author_email="[EMAIL PROTECTED]",
url="http://a.b.c";,
packages=['foopkg'],
scripts=['scripts/*.py'],
data_files=[('/usr/local/bin', ['scripts/myprj.py
Hello,
I'm seeking a read method that will block until new data is available. Is
there such a python function that does that?
Thanks,
Steven Howe
--
http://mail.python.org/mailman/listinfo/python-list
Hello everyone,
I'm trying to work through a bit of a logic issue I'm having with a
script I'm writing. Essentially, I have a list that's returned to
me from another command that I need to regroup based on some aribitrary
length.
For the purposes of this question, the list will be:
t = [ "a", "b
27;b', 'a', 't'], ['c', 'a', 't']]
Klaus,
Thanks for the fast reply! Had I taken the time to look at the
list-type docs (which I did to understand how you were spliting the
list), I'd probably have seen the slicing with step option. Another
RTFM issue for me.
Thanks again,
Steven
--
http://mail.python.org/mailman/listinfo/python-list
TechKicks.com is a community based technology site. It specializes in
Hi-Technologies like Robotics, ERP, GPS, Python, Haskell, Lisp, Ruby
On Rails,
and common techs like c#, PHP, Java, Sql and many more. Individual
users of the site submit and review stories, the most popular of which
make it to t
need to send a signal.
Just exit the server process and the worker threads will die (assuming
of course, you set .setDaemon(True) before starting each worker
thread).
Steven Rumbalski
--
http://mail.python.org/mailman/listinfo/python-list
'double(%s) => %2s\n' % (n, result))
results.close()
--- end of call_double.pyw ---
--- double.rb ---
while true
puts $stdin.gets().strip!.to_i * 2
STDOUT.flush
end
--- end of double.rb ---
thanks for any help,
Steven Rumbalski
--
http://mail.python.org/mailman/listinfo/python-list
uot;"
A couple of comments follow about when to merge Python 3 support. So
it looks like they are almost there.
Conclusion: 2 of 4 dependencies that Twisted needs to port to Python
3 show strong progress towards completing the port.
Steven Rumbalski
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 07 May 2013 15:17:52 +0100, Steve Simmons wrote:
> Good to see jmf finally comparing apples with apples :-)
*groans*
Truly the terrible pun that the terrible hijacking deserves.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
scaped.
If you have an artist with control characters in their name, like newline
or carriage return or NUL, I think it is fair to just drop the control
characters and then give the artist a thorough thrashing with a halibut.
Does your mapping really need to be guaranteed reversible? If
On Wed, 08 May 2013 00:13:20 -0400, Dave Angel wrote:
> On 05/07/2013 11:40 PM, Steven D'Aprano wrote:
>>
>>
>>
>> These are all Unicode characters too. Unicode is a subset of ASCII, so
>> anything which is ASCII is also Unicode.
>>
>>
>
m refactoring some of my own code that falls into
this anti-pattern. Die, enable method, die die die!)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 08 May 2013 11:13:33 +0100, Robert Kern wrote:
> On 2013-05-08 09:52, Steven D'Aprano wrote:
>> I'm looking for some help in finding a term, it's not Python-specific
>> but does apply to some Python code.
>>
>> This is an anti-pattern to a
ds the best, but it seems wierd to change
> the spelling of the class name to make it plural.
No weirder (note spelling) than changing any other noun. Whether you
change "int" to "ints" or FooEntry" to "FooEntries", you're still
changing it. That's how you make it plural.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
or do
you expect it to look like [2, 7, 6, 1]?
The normal interpretation of "one or more Foo" is that we're talking
about Foo *instances*, not subclasses of Foo. If that is not that case,
then the onus is on the author of the documentation to make it clear that
they are talking about s
to be able
> to find your stuff in a search engine some day, don't play cute with
> your name.
Googling for "the the" (including quotes) brings up 145 million hits,
nine of the first ten hits being relevant to the band.
On the other hand, I wouldn't want to be in a band called "The Beetles".
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Say, if you called
yourself "Hard Rock Band", and did hard rock. But then, googling for
"Heavy Metal" alone brings up the magazine as the fourth hit, so if you
get famous enough, even that won't work.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 08 May 2013 14:27:53 +, Duncan Booth wrote:
> Steven D'Aprano wrote:
>
>> I'm looking for some help in finding a term, it's not Python-specific
>> but does apply to some Python code.
>>
>> This is an anti-pattern to avoid. The idea i
On Thu, 09 May 2013 02:42:01 +, Dan Sommers wrote:
> On Wed, 08 May 2013 08:52:12 +0000, Steven D'Aprano wrote:
>
>> This is an anti-pattern to avoid. The idea is that creating a resource
>> ought to be the same as "turning it on", or enabling it, or similar.
code like this:
n = int(int(len(something)) + int(1))
just to be sure that the result is explicitly an int and not just
implicitly an int. Suppose some Javascript programmer was reading the
code, and they thought that 1 was a floating point value. That would be
bad!"
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
computation models are exactly equivalent.
This is like saying that Cartesian coordinates and polar coordinates are
so radically different that they cannot possibly both describe the same
space.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
combs.append((x, y))
Apart from not defined combs, those two pieces of code are equivalent.
So what is your question?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 09 May 2013 18:23:31 +1000, Cameron Simpson wrote:
> On 09May2013 19:54, Greg Ewing wrote:
> | Steven D'Aprano wrote:
> | > There is no sensible use-case for creating a file WITHOUT OPENING
> | > it. What would be the point?
> |
> | Early unix systems often u
d stack trace ending with
>
> InvalidStateError: initialize() needs to be called before
> do_stuff()
>
> Or something worse.
Exactly.
Thank you Wayne, that's a great help.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 09 May 2013 09:07:42 -0400, Roy Smith wrote:
> In article <518b32ef$0$11120$c3e8...@news.astraweb.com>,
> Steven D'Aprano wrote:
>
>> There is no sensible use-case for creating a file without opening it.
>
> Sure there is. Sometimes just creating the
an "always on" device, provided it hasn't wound down or
have a flat battery. Your fire alarm is "always on".
I must admit I am astonished at how controversial the opinion "if your
object is useless until you call 'start', you should automatically call
'start' when the object is created" has turned out to be.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 09 May 2013 23:09:55 -0400, Roy Smith wrote:
> In article <518c5bbc$0$29997$c3e8da3$54964...@news.astraweb.com>,
> Steven D'Aprano wrote:
>
>> I must admit I am astonished at how controversial the opinion "if your
>> object is useless until you c
On Fri, 10 May 2013 09:36:43 +1000, Cameron Simpson wrote:
> On 09May2013 11:30, Steven D'Aprano
> wrote:
> | On Thu, 09 May 2013 18:23:31 +1000, Cameron Simpson wrote:
> |
> | > On 09May2013 19:54, Greg Ewing wrote:
> | > | Steven D'Aprano wrote:
> | &g
On Fri, 10 May 2013 01:50:09 -0400, Roy Smith wrote:
> In article <518c7f05$0$29997$c3e8da3$54964...@news.astraweb.com>,
> Steven D'Aprano wrote:
>
>> there is no way to create a C file descriptor in a closed state. Such a
>> thing does not exist. If you hav
On Fri, 10 May 2013 06:22:31 +, Dan Sommers wrote:
> On Fri, 10 May 2013 05:03:10 +0000, Steven D'Aprano wrote:
>
>>>>> There is no sensible use-case for creating a file OBJECT unless it
>>>>> initially wraps an open file pointer.
>
>> So
p://xkcd.com/1209/
>>
>> --
>>
>>
>> This reflects a lack of understanding of Unicode.
>
> By the skywriter, or by the two on the ground, or by Randall Munroe?
Obviously by all three. It takes *hours* to execute
'è'*1000.replace('è
On Fri, 10 May 2013 17:59:26 +0100, Nobody wrote:
> On Thu, 09 May 2013 05:23:59 +0000, Steven D'Aprano wrote:
>
>> There is no sensible use-case for creating a file without opening it.
>> What would be the point? Any subsequent calls to just about any method
>> will
ot the one I
read all those many moons ago.
I never intended to give the impression that *any* use of a separate
"enable" method call was bad. I certainly didn't intend to be bogged
down into a long discussion about the minutia of file descriptors in
C, but it was educational :-)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ling that "Citizen Kant" is version 2.0 of
8 Dihedral.
Of course, I could be wrong.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
R. Hofstadter.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 12 May 2013 04:15:30 -0400, Devin Jeanpierre wrote:
> On Sun, May 12, 2013 at 1:17 AM, Steven D'Aprano
> wrote:
>> On Sat, 11 May 2013 21:45:12 -0700, rusi wrote:
>>
>>> I have on occasion expressed that newcomers to this list should be
>>> trea
rewdriver than driving screws.
> what's the single and most
> basic result one can expect from "interacting" with it directly
> (interactive mode)?
For your purposes, what is so special about interactive mode that you
single it out in this way? Interactive mode is just
ernal states, any input to the device, plus the transition rules
between them.
Python is not well-modelled as a Finite State Machine. Python is
equivalent in computing power to a Turing Machine, while Finite State
Machines are much weaker, so there are things that Python can do that a
FSM cannot
t; Maybe It'd be good if I explain myself a bit more. What I'm trying here
> is to grasp Python from the game's abstraction point of view, as if it
> were, for example, chess.
A lousy analogy. Python is nothing like chess. You might as well try to
understand Python as if it were a toothbrush.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
by trying to reason
from first principles (as Plato may have done) instead of empirical study
(as Aristotle or Bacon may have done). Knowledge of how things actually
are beats understanding of how they ought to be every time.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
e worth reading.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
se (red = 'red'), in that it would display
nicely and is going to provide easy to debug values. So nope.
[end quote]
Missing the point entirely. The *whole point* of enum red is that it WILL
display as 'red', even though it wraps an underlying value of . So this is a non-iss
vice'
... GREEN = 'green'
... EXPERIENCED = 'experienced'
... MASTER = 'master'
...
py>
py> Colours.GREEN == Experience.GREEN
True
Oops.
It's very easy to make something which does a few things that enums
should do, and call it an Enum. It's much harder to do a lot of things
that enums should do.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
greater than" and "not equal to". So if x was a NAN, then you
could have pseudo-code like this:
x != y # true
x <> y # false
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
e zen stand out here:-
>
> Explicit is better than implicit.
> in the face of ambiguity refuse the temptation to guess.
!= is explicit.
There is no ambiguity that needs to be guessed.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
my
> finger against the skin of the snake.
Python is not named after the snake, but after Monty Python the British
comedy troupe. And they picked their name because it sounded funny.
http://en.wikipedia.org/wiki/Monty_Python
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 14 May 2013 19:01:38 -0400, Dennis Lee Bieber wrote:
> On 14 May 2013 05:09:48 GMT, Steven D'Aprano
> declaimed the following in
> gmane.comp.python.general:
>> The <> operator comes from Pascal, where it was used as "not equal"
>> since
>
&
is a
simplified version of multiple inheritance that avoids most of the
complications.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
? It's not
necessary for the package to actually send the emails, dumping them into
an mbox is sufficient.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
file as well.
Another solution may be to add this to the beginning of your script:
os.setcwd('path/to/WC')
but that's a crappy solution, you generally don't want to be changing the
working directory from inside scripts if you can avoid it.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
will find the same moduleZ:
# Relative to the current module:
from . import moduleZ
# Relative to the parent of the current module:
from ..subpackage import moduleZ
from .. import subpackage.moduleZ
# Absolute:
import package.subpackage.moduleZ
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
bytes, then
use a for-loop instead of a while loop:
maxn = calculation(...)
with open(filename, 'w') as f:
for i in xrange(maxn):
f.write('%d\n' % i)
2) Write an extension module in C that writes to the file.
3) Get a faster hard drive, and avoid writing over a network.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
. My
prediction is that the call to f.write() and f.close() probably take a
fraction of a second, and nearly all of the rest of the time is taken by
other calculations.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
profiler, it is a little faster:
[steve@ando ~]$ time python fasterwrite.py
real0m16.187s
user0m13.553s
sys 0m0.508s
Although it is still slower than the heavily optimized dd command,
but not unreasonably slow for a high-level language:
[steve@ando ~]$ time dd if=fasterwrite.dat of=copy.dat
90781+1 records in
90781+1 records out
46479922 bytes (46 MB) copied, 0.737009 seconds, 63.1 MB/s
real0m0.786s
user0m0.071s
sys 0m0.595s
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ple, strange things
happen:
py> "%s" % (23,) # tuple with one item looks like an int
'23'
py> "%s" % (23, 42) # tuple with two items fails
Traceback (most recent call last):
File "", line 1, in
TypeError: not all arguments converted during string for
ally stable and conservative as Python. Possibly even more so.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
I believe Apple used
> for "new line"...
I can't comment about TRS, but classic Apple Macs (up to System 9) used
carriage return \r as the line separator.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
l('123')
123
py> ast.literal_eval('[123, None, "spam"]')
[123, None, 'spam']
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ises an exception if the
expression contains an underscore. Underscores are usually the key to
breaking eval, so refusing to evaluate anything with an underscore raises
the barrier very high.
And even with all those defences, I wouldn't allow untrusted data from
the Internet anywhere near this. Just because I can't break it, doesn't
mean it's safe.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 21 May 2013 05:53:46 +0300, Carlos Nepomuceno wrote:
> BTW, why I didn't find the source code to the sys module in the 'Lib'
> directory?
Because sys is a built-in module. It is embedded in the Python
interpreter.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 21 May 2013 08:30:03 +0200, Frank Millman wrote:
> On 20/05/2013 18:12, Steven D'Aprano wrote:
>> Personally, I would strongly suggest writing your own mini- evaluator
>> that walks the list and evaluates it by hand. It isn't as convenient as
>> just calli
For maths nerds like me, this is too cool for words:
http://www.johndcook.com/blog/2013/04/30/recognizing-numbers/
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
e Ruby.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
0 is irrelevant. If somebody is trying to
"future proof" their code for a version that *may never exist*, and if it
does exist is likely to be six or eight years away from even starting the
design phase, they are wasting their time. It is hard enough to track a
moving target, it is i
in, but it's also more or less impossible to do in
full generality. And again, what you are running will be something
different than Python, it will be Python plus a pre-processor.
Don't fight the language. You will lose.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
cipe on ActiveState.
https://pypi.python.org/pypi
http://code.activestate.com/recipes/langs/python/
Thank you.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
t it has been deprecated (or soon will be deprecated, or one
day will be deprecated, and therefore code using it is bad) is relatively
widespread on the Internet.
Glad to have you back here!
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
as a
powerful (and therefore dangerous) tool, and avoid it whenever you don't
*need* it, there is no reason to be irrational about it :-)
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
once
every 3628800 times, and for a twenty-item list, once in
243290200817664 times. But of course these are *random*, and there's
always a chance of this:
http://dilbert.com/strips/comic/2001-10-25
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
= [name, arg]
# Instantiate.
instance = TABLE[argv[0]](argv[1])
print instance
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
But merely shuffling
your data around to avoid spurious correlations is not one of them. Save
yourself a lot of development effort, and debugging, and just use
random.shuffle.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
hon code.
tally = 0
for item in list_of_items:
if item == 0:
tally = tally + 1
print "The number of zeroes equals", tally
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 25 May 2013 16:41:58 +1000, Chris Angelico wrote:
> On Sat, May 25, 2013 at 4:38 PM, zoom wrote:
>> But why would anyone want to use IPv6?
>
> I hope you're not serious :)
He's planning to drop off the Internet once the IP address run out.
--
Steven
-
On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote:
> def random_number():
> return 7
I call shenanigans! That value isn't generated randomly, you just made it
up! I rolled a die *hundreds* of times and not once did it come up seven!
--
Steven
--
http://mail.python.
On Fri, 24 May 2013 23:05:17 -0700, lokeshkoppaka wrote:
> On Saturday, May 25, 2013 11:27:38 AM UTC+5:30, Steven D'Aprano wrote:
>> tally = 0
>> for item in list_of_items:
>> if item == 0:
>> tally = tally + 1
>>
>> print "The numbe
rl -d to get a debugged
> output is there any option in python.
Yes. Instead of calling your script like this:
python myscript.py
call it like this:
python -m pdb myscript.py
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 26 May 2013 01:41:58 +1000, Chris Angelico wrote:
> On Sun, May 26, 2013 at 12:28 AM, Steven D'Aprano
> wrote:
>> On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote:
>>
>>> def random_number():
>>> return 7
>>
>> I call shena
ting 6, gives you a close approximation to a Gaussian random
variable with mean 0 and standard deviation 1.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ity policies.
Or, more likely, *not* implemented in firewalls with *inappropriately*
coded security policies.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
> being arbitrarily in the hands of the technology. So I would be able to
> talk to the file server across the street, but only IF its admin lets
> me.
Or when (not if) you find a vulnerability in the particular firewall.
Make no mistake: the most secure entry point is the
an be distinguished from zero. The way to test whether
x equals zero is:
x == 0
What the above actually tests for is whether x is so small that (1.0+x)
cannot be distinguished from 1.0, which is not the same thing. It is also
quite arbitrary. Why 1.0? Why not (0.0001+x)? Or (0.0001+x)? Or
(1.0+x)?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
fe, but it has the benefit that if the "near zero"
condition ever changes to become much more expensive, you don't have to
worry about reordering the tests because they're already in the right
order.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
re I couldn't find.
These are the standard C operating system and file system error codes,
not Python exceptions.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ata, but you want to
detect changes to whitespace, blank lines, or other changes that make no
difference to the JSON data, then there is no need to care that this is
JSON data. Just treat it as text, and use the difflib library.
http://docs.python.org/2/library/difflib.html
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
ocal variable to the new list, it takes the existing list, and replaces
each value inside it with the values taken from the new list. For example:
py> mylist = [100, 200, 300, 400, 500, 600]
py> mylist[3:5] = ['A', 'B', 'C']
py> mylist
[100, 200, 300, 'A', 'B', 'C', 600]
py> mylist[1:] = [99, 98, 97]
py> mylist
[100, 99, 98, 97]
Any questions?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 27 May 2013 13:46:50 +0100, Fábio Santos wrote:
> Speaking of PEPs and exceptions. When do we get localized exceptions?
We're waiting for you to volunteer. When can you start?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
'):
... m = 256*m + b
...
py> m == n
True
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
the docs after int.to_bytes is int.from_bytes:
And I can't believe I missed that too :-(
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
n. But I don't think that exceptions should otherwise
be localised.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
1 - 100 of 15563 matches
Mail list logo