Re: UTF-8 Support of Curses in Python 2.5

2007-07-21 Thread Andrey
Yes, it does solve the problem.
Compile python with ncursesw library.
Btw Ubuntu 7 has it "out of the box".


> Hi All,
> 
> Recently I ran into a problem with UTF-8 surrport when using curses
> library in python 2.5 in Fedora 7. I found out that the program using
> curses cannot print out unicode characters correctly on UTF-8 enabled
> console. I googled around and got an impression that the reason for
> this problem is that python is linked with libcurses library instead
> of libcursesw. The latter one is said to be able to solve this
> problem. Has anybody tried this? How to manually let python use
> libcursesw? Thanks a lot!
> 
> Here is a test program:
> 
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
> import curses
> def keyloop(stdscr):
> # Clear the screen and display the menu of keys
> stdscr_y, stdscr_x = stdscr.getmaxyx()
> menu_y = (stdscr_y-3)-1
> str = u'This is my first curses python program. Press \'q\' to
> exit. (¤£™)'
> stdscr.addstr(menu_y, 4, str.encode('utf-8'))
> xpos = stdscr_x / 2
> ypos = stdscr_y / 2
> while (1):
> stdscr.move(ypos, xpos)
> c = stdscr.getch()
> if 0 < c < 256:
> c = chr(c)
> if c in 'Qq': break
> else: pass
> elif c == curses.KEY_UP and ypos > 0:   ypos -= 1
> elif c == curses.KEY_DOWN and ypos < stdscr_y - 1:  ypos += 1
> elif c == curses.KEY_LEFT and xpos > 0: xpos -= 1
> elif c == curses.KEY_RIGHT and xpos < stdscr_x - 1: xpos += 1
> else: pass
> def main(stdscr):
> keyloop(stdscr)
> if __name__ == '__main__':
> curses.wrapper(main)

-- 
http://mail.python.org/mailman/listinfo/python-list

simpleJSON pack binary data

2007-07-21 Thread Andrey
Hi

I donno if this is the right place to ask for this question, anyway

Is it possible to pack binary data into simplejson?

d={}
d['date'] = xx
d['name'] = xx
d['size'] = x

d['imageBinaryDataJpeg'] = jpegBinaryDataFromcStringIOStringIO

simplejson.dumps(d)

when i do this, it raises a UTF8 decode error, probably about the binary 
image data

My question is, anyone will suggest a workaround to this error?
i really like to pack my raw image data into the JSON, so my other 
programming script can read the array easily

Thanks
An K




-- 
http://mail.python.org/mailman/listinfo/python-list


2 daemons write to a single file /w python file IO

2007-09-11 Thread Andrey
HI

i have a newbie question about the file() function.
I have 2 daemons running on my linux box.

1 will record the IDs to a file - logs.txt
other 1 will open this file, read the IDs, and then "Clean up the 
file" -logs.txt

Since these 2 daemons will run every 2-5mins, I think this will crash, isn't 
it? When both daemons try to write to the file at the same time.

I am wondering if this won't crash, OR if there is some simple high-level 
functions can lock the file while writing...
I also wonder if one side locked the file, what happens if the other side 
try to open this locked file? raise error? so i also need to write a loop to 
wait for the file to release locking?

seems a basic easy thing but i just cannot find an simple answer.
I always advoid this issue by putting them in mysql (well, fast and hassle 
free for locking)

Thanks
Jay



-- 
http://mail.python.org/mailman/listinfo/python-list


Mysql class works like php

2007-10-04 Thread Andrey
Hi

just a quick question about using MySQL module... are there any api / class 
available to give a higher level in working with Mysql in python?
such as
db.fetch_array(),
db.fetch_rows(),
db.query(),
for eachrow in db.fetch_array():


just as easy as PHP?
I think someone might already done this, so i dont have to re-invent the 
wheel, but i have no luck in google, so wondering if anyone might know such 
thing exists...

thanks
Andrey 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Test Bank for Governing Texas, 3rd Edition by Champagne Harpham

2017-09-15 Thread andrey . estrada2
On Sunday, July 9, 2017 at 5:58:45 AM UTC-6, Test Banks wrote:
> Greetings, 
> 
> You can get Test Bank for " Governing Texas, 3rd Edition by Anthony 
> Champagne, Edward J. Harpham, Jason P. Casellas " at very reasonable price. 
> Our team is available 24/7 and 365 days / year to respond your requests. Send 
> us an email at pro.fast(@)hotmail(dot)com 
> 
> Place your order at PRO.FAST(@)HOTMAIL(DOT)COM 
> 
> ISBN Numbers for this book (ISBN-10: 0393283674 and ISBN-13: 9780393283679) 
> 
> GOVERNING TEXAS, 3RD EDITION BY CHAMPAGNE HARPHAM TEST BANK
> 
> You can also email for other Political Science books Solutions and Test Bank 
> at low prices and our team will try to get all resources you need. 
> 
> Do not post your reply here. Simply send us an email at PRO.FAST (AT) HOTMAIL 
> (DOT) COM 
> 
> Cheers


I am interested in the testbank for this book. What is the price ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Just added AnyChart JS Charts integration templates for easier dataviz with Python (+ Flask/Django) and MySQL

2016-12-29 Thread andrey . khachaturov
Hi all,

We at AnyChart JS Charts http://www.anychart.com have just released a series of 
20+ integration templates to help web developers add interactive charts, maps, 
stock and financial graphs, Gantt charts, and dashboards to web apps much 
easier, no matter what your stack is.

In particular, now there are two templates for Python in our Technical 
Integration collection http://www.anychart.com/integrations/, all distributed 
under the Apache 2.0 License and forkable on GitHub:

1) Python, Flask and MySQL
https://github.com/anychart-integrations/python-flask-mysql-template

2) Python, Django and MySQL
https://github.com/anychart-integrations/python-django-mysql-template

You are welcome to check those out and ask your questions if any.

Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


embedded scripts debugging

2005-01-07 Thread Andrey Tatarinov
Hi all.
I have custom resource editor and wish python to be scripting language 
in it. But I don't want to lose ability of debugging which I currently 
have implementing all logic in C++.

So the question is: Is there suitable library for simple python gui 
debugger, or may be there are some other techniques for debugging 
embedded scripts?
--
http://mail.python.org/mailman/listinfo/python-list


python3: 'where' keyword

2005-01-07 Thread Andrey Tatarinov
Hi.
It would be great to be able to reverse usage/definition parts in 
haskell-way with "where" keyword. Since Python 3 would miss lambda, that 
would be extremly useful for creating readable sources.

Usage could be something like:
>>> res = [ f(i) for i in objects ] where:
>>> def f(x):
>>> #do something
or
>>> print words[3], words[5] where:
>>> words = input.split()
- defining variables in "where" block would restrict their visibility to 
one expression

- it's more easy to read sources when you know which part you can skip, 
compare to

>>> def f(x):
>>> #do something
>>> res = [ f(i) for i in objects ]
in this case you read definition of "f" before you know something about 
it usage.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-08 Thread Andrey Tatarinov
Bengt Richter wrote:
It also allows the necessary but uninteresting setup for an expression 
to be moved "out of the way", bringing the expression that does the real 
work to prominence.
Killer app for this keyword:
class C(object):
 x = property(get, set) where:
   def get(self):
 return "Silly property"
   def set(self, val):
 self.x = "Told you it was silly"
Yes, that is cool and it _is_ an interesting idea. Are suites nestable? E.g., is this legal?
...
And, is the whole thing after the '=' an expression? E.g.,
  x = ( foo(x) where:
 x = math.pi/4.0
  ) where:
 def foo(x): print 'just for illustration', x
or is this legal?
  for y in ([foo(x) for x in bar] where:
 bar = xrange(5)
): baz(y) where:
def baz(arg): return arg*2
Not trying to sabotage the idea, really, just looking for clarification ;-)
yes, all your examples are correct. And that's the way I'd like to use 
this feature.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-08 Thread Andrey Tatarinov
Nick Coghlan wrote:
It also allows the necessary but uninteresting setup for an expression 
to be moved "out of the way", bringing the expression that does the 
real work to prominence.
Killer app for this keyword:
class C(object):
  x = property(get, set) where:
def get(self):
  return "Silly property"
def set(self, val):
  self.x = "Told you it was silly"
oh, that's great! I can't imagine prettier example
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: accessing the result of 'if'

2005-01-09 Thread Andrey Tatarinov
Carl Banks wrote:
As a compromise, howabout:
. if m > 20 where m=something():
. do_something_with(m)
That's good, but first idea was about 'where' block that contains any 
expressions, that we need, for example function definition. the syntax 
you proposed has same problems as 'lambda'.

The main problem here (as some would see it) is that you can't do
something this:
. if m > 20 where (def m(): a(); b()):
exactly
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
Peter Hansen wrote:
 >>> print words[3], words[5] where:
 >>> words = input.split()
- defining variables in "where" block would restrict their visibility 
to one expression
Then your example above doesn't work...  print takes a
sequence of expressions, not a tuple as you seem to think.
sorry, I used "expression" carelessly.
I mean that
>>> print words[3], words[5]
is a single expression
(and that would be in Python 3, when print would be subtituted with 
write()/writeln()).
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
Paul Rubin wrote:
You mean I can't say
   # compute sqrt(2) + sqrt(3)
   x = (sqrt(a) where:
 a = 2.) \
   + sqrt (a) where:
   a = 3.
No, I'd prefer to not embed 'where' into expression.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
Nick Coghlan wrote:
Current:
  assignment_stmt ::= (target_list "=")+ expression_list
  augmented_assignment_stmt ::=target augop expression_list
New:
  assignment_stmt ::= (target_list "=")+ expression_list [where_clause]
  augmented_assignment_stmt ::=target augop expression_list 
[where_clause]
  where_clause ::= "where" ":" suite

So the expressions in existing compound statements (for, while, if, 
elif) would be out of luck. You could conceivably add the 'where' clause 
to the end of those as well, to give statement local variables that 
apply to the whole compound statement:
Nick, you're good at formalization, thanks again.
So it seems that people loved the idea of 'where' keyword, may be it's 
time to think about PEP draft? I appreciate any help (cause my english 
is not that good =)).
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
Nick Coghlan wrote:
sorry, I used "expression" carelessly.
I mean that
 >>> print words[3], words[5]
is a single expression
(and that would be in Python 3, when print would be subtituted with 
write()/writeln()).
'statement' is the appropriate word in Python's grammar.
thanks )
And I don't think we'd actually have to wait for Python 3 for this, we'd 
just have to do the __future__ dance in order to introduce the new keyword.
resonable, I mentioned Python3 as something in not that near future, 
that'd be great to think of it earlier
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
Paul Rubin wrote:
What would be the advantage of that over this?
. x = sqrt(a) + sqrt(b) where:
. a = 2.0
. b = 3.0
The idea of "where" is to allow re-using variable names instead of
having to keep track of which ones are in use.  I just tried to give a
very simple example of how you might do that more than once in a
statement.
then I'd write something like this:
x = a + b where:
a = sqrt(n) where:
n = 2.
b = sqrt(n) where:
n = 3.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
Alex Martelli wrote:
Indeed, the fact that many MANY more people are familiar with SQL than
with Haskell may be the strongest practical objection to this choice of
syntax sugar; the WHERE clause in an SQL SELECT has such wildly
different semantics from Haskell's "where" that it might engender huge
amounts of confusion.  I.e., reasoning by analogy with SQL only, one
might reasonably expect that minor syntax variations on:
print a, b where a = b
could mean roughly the same as "if a==b: print a, b", rather than
hmm... SQL-ish associations are good too, if you think a little deeper 
then common post-effect of using SQL "where" keyword.

print a, b where a = b
means a==b in statement "print a, b"
roughly the same as:
a = b
print a, b
I wonder if 'with', which GvR is already on record as wanting to
introduce in 3.0, might not be overloaded instead.
using 'with', is some way unnatural for my point of view (may be because 
 translations of 'with' and 'where' into russian, are way different and 
'where' translation reads as natural language while 'with' does not).

I'd like to keep 'where' keyword for proposal, but semantics are more 
important, so in case I do not mind for other keyword.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-09 Thread Andrey Tatarinov
And about examples for usage "where" keyword
reading http://manatee.mojam.com/~skip/python/fastpython.html I 
understand that almost every example should use that keyword =)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pygame and pyopengl with py2exe ?

2005-01-09 Thread Andrey Tatarinov
Nyx42 wrote:
Second program (pygame + pyopenGL):
Py2exe can't import OpenGL.GL and OpenGL.GLU :(
about that, may be names of imports are generated in runtime, so you can 
try to specify them directly

options = {"py2exe": {"packages": ["OpenGL.GL","OpenGL.GLU"]}},
--
http://mail.python.org/mailman/listinfo/python-list


Python3: on removing map, reduce, filter

2005-01-09 Thread Andrey Tatarinov
Hi.
How does GvR suggestions on removing map(), reduce(), filter() correlate 
with the following that he wrote himself (afaik):

http://www.python.org/doc/essays/list2str.html
?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Andrey Tatarinov
Paul Rubin wrote:
How does GvR suggestions on removing map(), reduce(), filter()
correlate with the following that he wrote himself (afaik):
http://www.python.org/doc/essays/list2str.html
I think that article was written before list comprehensions were added
to Python.
anyway list comprehensions are just syntaxic sugar for
>>> for var in list:
>>> smth = ...
>>> res.append(smth)
(is that correct?)
so there will be no speed gain, while map etc. are C-implemented
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python3: on removing map, reduce, filter

2005-01-09 Thread Andrey Tatarinov
Steve Holden wrote:
Andrey Tatarinov wrote:
Hi.
How does GvR suggestions on removing map(), reduce(), filter() 
correlate with the following that he wrote himself (afaik):

http://www.python.org/doc/essays/list2str.html
>
And note that the summary in the conclusiogn BEGINS with "Rule number 
one: only optimize when there is a proven speed bottleneck", which seems 
to adequately imply that straightforward code is to be preferred unless 
speed requirements override that.
My main question was: "how could be this advices applied, when map, 
reduce and filter would be removed?"

but earlier I got answers about speed of list comprehensions, though 
they need to be proved.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python3: 'where' keyword

2005-01-10 Thread Andrey Tatarinov
Nick Coghlan wrote:
And about examples for usage "where" keyword
reading http://manatee.mojam.com/~skip/python/fastpython.html I 
understand that almost every example should use that keyword =)
I suspect polluting the outer namespace would still be faster, since 
Python wouldn't have to create the extra level of scoping all the time.
sure, but just a little bit slower =)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-10 Thread Andrey Tatarinov
Nick Coghlan wrote:
Abstract

  The proposal is to add the capacity for statement local namespaces to 
Python. This allows a statement to be placed at the current scope, while 
the statement's 'setup code' is indented after the statement::

   with:
  
I think using 'with' keyword can cause some ambiguity. for example I 
would surely try to write

>>> x = a+b with self:
>>> b = member
and using with at the end of block brings more ambiguity:
>>> stmt1()
>>> stmt2()
>>> with self:
>>> member = stmt3()
compare to:
>>> stmt1()
>>> stmt2()
>>> with:
>>> variable = stmt3()
a way different semantics with just one word added/deleted.
--
http://mail.python.org/mailman/listinfo/python-list


Re: exceptions and items in a list

2005-01-10 Thread Andrey Tatarinov
rbt wrote:
If I have a Python list that I'm iterating over and one of the objects 
in the list raises an exception and I have code like this:

try:
do something to object in list
except Exception:
pass
Does the code just skip the bad object and continue with the other 
objects in the list, or does it stop?
# skip bad object and continue with others
for object in objects:
try:
#do something to object
except Exception:
pass
# stop at first bad object
try:
for object in objects:
#do something to object
except Exception:
pass
--
http://mail.python.org/mailman/listinfo/python-list


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-11 Thread Andrey Tatarinov
Nick Coghlan wrote:
Semantics
-
The code::
 with:
   
translates to::
def unique_name():


unique_name()
Bleh. Not only was my proposed grammar change wrong, my suggested 
semantics are wrong, too.

Raise your hand if you can see the problem with applying the above 
semantics to the property descriptor example.

So I think the semantics will need to be more along the lines of 
"pollute the namespace but mangle the names so they're unique, and the 
programmer can *act* like the names are statement local".

This will be much nicer in terms of run-time performance, but getting 
the locals() builtin to behave sensibly may be a challenge.
afair you told yourself that
var =  where:

translates to:
def unique_name():

return 
var = unique_name()
in this case class gets unique_name() function? is it that bad?
anyway I'd prefer to change semantics deeper. adding new statement-only 
scope and adding our suite-definitions there.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-11 Thread Andrey Tatarinov
So of the four keywords suggested so far ('where', 'with', 'in', 
'using'), I'd currently vote for 'using' with 'where' a fairly close 
second. My vote goes to 'using' because it has a fairly clear meaning 
('execute the statement using this extra information'), and doesn't have 
the conflicting external baggage that 'where' does.
I should agree with you =)
Though I love "with" for historical reasons and addiction to functional 
languages "using" is not that bad and I do not mind using it. =)
--
http://mail.python.org/mailman/listinfo/python-list


Re: embedded scripts debugging

2005-01-11 Thread Andrey Tatarinov
Miki Tebeka wrote:
So the question is: Is there suitable library for simple python gui 
debugger, or may be there are some other techniques for debugging 
embedded scripts?
What I usually do is add
from pdb import set_trace
in the embedded module somewhere and then add a call to set_trace
(breakpoint) whenever I with.
When the code reaches the call to set_trace, you'll have pdb prompt and you
can debug as you like.
Note that you can't add breakpoint dynamically this way.
Thanks, I gathered pros and cons of embedding and decided to use python 
extending (i.e. creating python modules) instead of embedding. Happily I 
have an option to choose
--
http://mail.python.org/mailman/listinfo/python-list


Re: else condition in list comprehension

2005-01-13 Thread Andrey Tatarinov
Steve Holden wrote:
Nick Coghlan wrote:
Luis M. Gonzalez wrote:
Hi there,
I'd like to know if there is a way to add and else condition into a
list comprehension. I'm sure that I read somewhere an easy way to do
it, but I forgot it and now I can't find it...
for example:
z=[i+2 for i in range(10) if i%2==0]
what if I want i to be "i-2" if i%2 is not equal to 0?
Hmm:
z = [newval(i) for i in range(10)] using:
def newval(x):
if x % 2:
return x - 2
else:
return x + 2
Just some more mental twiddling relating to the thread on statement 
local namespaces.

I presume the point of this is to avoid polluting the local namespace 
with "newval". I further presume you also have plans to do something 
about "i"? ;-)
no, the point is in grouping definition of newval() with place where it 
is used.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-13 Thread Andrey Tatarinov
Nick Coghlan wrote:
Nick Coghlan wrote:
Semantics
-
The code::
 with:
   
translates to::
def unique_name():


unique_name()
I've come to the conclusion that these semantics aren't what I would 
expect from the construct. Exactly what I would expect can't really be 
expressed in current Python due to the way local name bindings work. The 
main thing to consider is what one would expect the following to print:

def f():
a = 1
b = 2
print 1, locals()
print 3, locals() using:
a = 2
c = 3
print 2, locals()
print 4, locals()
I think the least suprising result would be:
1 {'a': 1, 'b': 2} # Outer scope
2 {'a': 2, 'c': 3} # Inner scope
3 {'a': 2, 'b': 2, 'c': 3} # Bridging scope
4 {'a': 1, 'b': 2} # Outer scope
as for me, I would expect following:
1 {'a': 1, 'b': 2}
2 {'a': 2, 'b': 2, 'c': 3'}
3 {'a': 2, 'b': 2, 'c': 3'}
4 {'a': 1, 'b': 2}
otherwise that would be impossible to do calculations based on scope 
variables and "using:" would be useless =), consider example of usage:

current_position = 1
current_environment # = ...
current_a_lot_of_other_parameters # = ...
scores = [count_score(move) for move in aviable_moves] using:
def count_score(move):
#walking through current_environment
return score
--
http://mail.python.org/mailman/listinfo/python-list


Re: Statement local namespaces summary (was Re: python3: 'where' keyword)

2005-01-16 Thread Andrey Tatarinov
Nick Coghlan wrote:
# Anonymous functions
use res:
  def f(x):
d = {}
exec x in d
return d
in:
  res = [f(i) for i in executable]
as for me, I found construction "use :" unobvious and confusing.
Also there is great possibility to forget some of variables names.
I think that syntax

where:

is more obvious. (and we already have defined semantics for it)
we have two problems, that we try to solve
1) create method to nest scopes
2) create method to reverse execution order for better readability
"using:" solves both at once.
but your "use ... in ..." syntax shows, that you want to be able to 
solve 1) independently i.e. create nested scope without reversing 
execution order.

so, I can suggest one more keyword "do:", which will create nested 
scope, just as "def f(): ... ; f()" do (and that could be just syntaxic 
sugar for it.

so "use ... in ..." would look the following way:
do:
res = [f(i) for i in executable]
#some more equations here
using:
def f(x):
d = {}
exec x in d
return d
that seems good for me. of course if you want to return something from 
the nest scope you must show that variable is from parent scope.

// while writing that I realized that it's too complex to be implemented 
in python in that way. consider it as some type of brainstorming.
--
http://mail.python.org/mailman/listinfo/python-list


Re: protecting the python code.

2005-01-17 Thread Andrey Tatarinov
nell wrote:
First the "10x in advance" means thanks in advance.
The main importance of protecting my code is to save headache of
customers that want to be smart and change it and then complain on bugs
also you can try to use py2exe
--
http://mail.python.org/mailman/listinfo/python-list


Strange email.Parser error?

2005-08-18 Thread Andrey Smirnov
I am getting the following traceback after upgrading my app to Python
2.4.1.  It's telling me that there is an error in Parser.py.  It tells
me that 'fp.read(8192)' is given 2 arguments, but it is clearly not
true.  Does anybody know what's going on here?

Traceback (most recent call last):
  File "/opt/etext/lib/python2.4/site-packages/etext/enqueue.py", line
252, in work
worker(e.linkval, info)
  File "/opt/etext/bin/etreceive", line 30, in worker
result = decode.searchfile(f)
  File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
43, in searchfile
return Email(f)
  File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
510, in __init__
self.child.append(Email(mf))
  File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
404, in __init__
msg = Parser().parse(f)
  File "/opt/etext/lib/python2.4/email/Parser.py", line 65, in parse
data = fp.read(8192)
TypeError: read() takes exactly 1 argument (2 given)

Thanks,
Andre.

-- 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange email.Parser error?

2005-08-18 Thread Andrey Smirnov
Ah - this makes more sense.

Did the implementation of 'fp' file-like object change in 2.4.1 and it
no longer has a read()?

Andre.

Anthony Botrel wrote:
> Hi,
> 
> in the call fp.read(8192) the function read() gets 2 arguments :  and 
> <8192>
> 
> Member functions implicitely get their object as first argument, this
> is why you get this error. So you have 2 possibilities : either read()
> doesn't take an argument anymore, or read() is not a member of fp.
> 
> Anthony B.
> 
> On 8/18/05, Andrey Smirnov <[EMAIL PROTECTED]> wrote:
> 
>>I am getting the following traceback after upgrading my app to Python
>>2.4.1.  It's telling me that there is an error in Parser.py.  It tells
>>me that 'fp.read(8192)' is given 2 arguments, but it is clearly not
>>true.  Does anybody know what's going on here?
>>
>>Traceback (most recent call last):
>>  File "/opt/etext/lib/python2.4/site-packages/etext/enqueue.py", line
>>252, in work
>>worker(e.linkval, info)
>>  File "/opt/etext/bin/etreceive", line 30, in worker
>>result = decode.searchfile(f)
>>  File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
>>43, in searchfile
>>return Email(f)
>>  File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
>>510, in __init__
>>self.child.append(Email(mf))
>>  File "/opt/etext/lib/python2.4/site-packages/etext/decode.py", line
>>404, in __init__
>>msg = Parser().parse(f)
>>  File "/opt/etext/lib/python2.4/email/Parser.py", line 65, in parse
>>data = fp.read(8192)
>>TypeError: read() takes exactly 1 argument (2 given)
>>
>>Thanks,
>>Andre.
>>
>>--
>>
>>--
>>http://mail.python.org/mailman/listinfo/python-list
>>

-- 


_/_/_/   _/_/  _/ _/ Andre Smirnov
   _/   _/_/  _/_/   _/  CNS - DSE
  _/_/_/   _/_/  _/  _/ _/   303 272-8352 / x78352
 _/   _/_/  _/   _/_/Mailstop: UBRM05-203
_/_/_/_/_/_/   _/ _/

500 Eldorado boulevard
Broomfield, CO 80021





-- 
http://mail.python.org/mailman/listinfo/python-list


Re: uptime for Win XP?

2004-12-12 Thread Andrey Ivanov
>> I believe that "uptime" works from the console, but don't have a machine
>> to check it with...

> Doesn't work for me, but if you have win32all installed, you can get it
> from Python:
> >>> import win32api
> >>> print "Uptime:", win32api.GetTickCount(), "Milliseconds"
> Uptime: 148699875 Milliseconds

MSDN  recommends  another approach. They say, that you should retrieve
the  value  of "System Up Time" counter from HKEY_PERFORMANCE_DATA. In
theory,  you  can do it without win32all, by using _winreg module. All
you  need  is  to  know  a  counter  index,  which can be fetched from
registry.  On  my  system "System Up Time" counter has index "674", so
Python code should look like this:

>>> import _winreg
>>> value, type_code = _winreg.QueryValueEx(_winreg.HKEY_PERFORMANCE_DATA, 
>>> "674")
>>> print "Uptime: %s miliseconds" % (value,)

But in current implementation of _winreg it doesn't work. I've checked
the  sources  and  found  that  current  implementation doesn't handle
ERROR_MORE_DATA,  which  prevents  it  from retrieving any performance
counters. I'm thinking of bug/patch submission.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: uptime for Win XP?

2004-12-13 Thread Andrey Ivanov
[Peter Hanson]
> The real solution, in spite of the dozen alternatives we've
> now produced, seems to be to use the win32pdh library
> to access the "System"-> "System Up Time" value.  It
> claims to return an 8-byte value, which likely doesn't
> wrap quite so soon.  (And yes, remarkably, with the advent
> of Windows XP Pro it is now possible to keep a Windows
> machine running for longer than 49 days, even if it's
> used as a development machine.  Well, for Python development,
> anyway. ;-)
> 
> For the life of me, however, I can't figure out how to do it.

Here's how. :-)

=
import win32pdh

query = win32pdh.OpenQuery()
counter = win32pdh.AddCounter(query, r"\System\System Up Time")

win32pdh.CollectQueryData(query)

(bizzare_int, val) = win32pdh.GetFormattedCounterValue(counter, \
win32pdh.PDH_FMT_LONG)

print "Uptime: %s secs" % (val,)
==

Writting this script was harder than I initially thought due to
a lack of documentation for win32all. And I still don't know what
that bizzare_int value stands for (an error/status code?).

Well, the registry interface to counters is definitely easier to use,
but not available to Python at the moment :-(

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: uptime for Win XP?

2004-12-14 Thread Andrey Ivanov
>> Writting this script was harder than I initially thought due to
>> a lack of documentation for win32all. And I still don't know what
>> that bizzare_int value stands for (an error/status code?).

[Fredrik Lundh]
> if I'm not mistaken, the corresponding Win32 function is called
> PdhGetFormattedCounterValue, which has two [in] parameters
> (counter handle, format code) and two [out] parameters (counter
> type, counter value)
> 
> so "counter type" is a good guess.
> 
>  

[David Bolen]
> The pywin32 documentation tends not to duplicate information already
> available via MSDN (whether in a local installation or at
> msdn.microsoft.com) on the underlying Win32 API, so when in doubt,
> that's where to look.  Then, the pywin32 documentation will sometimes
> qualify how the Python interface maps that function.
> 
> But in particular, a general rule (as has already been posted) is that
> any out parameters are aggregated along with the overall result code
> into a result tuple.
> 
> -- David

Thanks for reply! MSDN did contain the answer, but I didn't noticed
it.

--
Andrey

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dot products

2004-12-19 Thread Andrey Tatarinov
Rahul wrote:
I want to compute dot product of two vectors stored as lists a and b.a
and b are of the same length.
one simple way is
sum(a[i]*b[i] for i in range(len(a)))
btw, imho the most "Pythonic" would be:
sum(i*j for (i,j) in zip(a,b))
--
http://mail.python.org/mailman/listinfo/python-list


Re: win32 process name

2004-12-22 Thread Andrey Ivanov
[phil]

> I need to know if a process is running.
> not just python.exe
> but python.exe myapp

> from win32all
> EnumProcesses gives me the pids, then
> OpenProcess(pid) gives me a handle.
> Then what?
> GetModuleFileNameEX?

It   won't   do   the   right  thing  for  you.  As  far  as  I  know,
GetModuleFileNameEx()  returns  the name of a particular DLL, but what
you need to know is a *commandline*. I think that this is not possible
at  all.  Microsoft's  examples  use named mutexes to test whether the
process  is  already running or not. It is quite easy. Here's a quick
example:

import sys
import win32event

STANDARD_ACCESS_READ = 131072

mutex_handle = None

try:
mutex_handle = win32event.OpenMutex(STANDARD_ACCESS_READ, False, "Test")
except:
pass

if mutex_handle:
sys.exit("Instance is already running")
else:
mutex_handle = win32event.CreateMutex(None, False, "Test")

try:
while 1:
pass
except:
pass


-- 
Andrey

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with os.listdir and delay with unreachable network drives on Windows

2004-12-23 Thread Andrey Ivanov
[Read Roberts]
> I wrote my own directory browser in order to get around a bug where 
> tkFileDialog.askdirectory()  can't handle non-ascii paths. However, I
> have a problem where I call os.listdir() on a  mapped network drive,
> e.g. os.listdir("Z:\\"), and if the network drive is unavailable, the
> UI hangs  until the OS returns with an exception because the network
> shared drive is unavailable.

>   I would like to work around this by simply not looking into  mapped
> drives that are not currently mounted.  Is there some way to check 
> the status of mapped drive to see if it is currently mounted, or a 
> better solution? ( I use the call win32api.GetLogicalDriveStrings() 
> to get the list of available drives).

> Also, is there any way to enumerate remote volumes that are mounted 
> by not mapped? I can't easily find this in the win32 stuff or via 
> googling. The win32net calls to enumerate servers and shares sound 
> likely, but don't show such volumes on my system, although I may not
> be using the right arguments.

> I have the current Windows binary install of Python 2.3.4 on my 
> Windows XP system.

Maybe  a  win32net.WNetGetUniversalName()  [expands drive to UNC name]
and   win32net.NetGetUseInfo()  [returns  various  info  on  UNC  name
including  status] will help you. I don't have a time to setup shares,
so I can't guarantee that this approach will work as you expect. First
function  might  raise an exception on disconnected devices, which you
will  need  to handle. You might also need win32file.GetDriveType() to
distinguish between remote and local drives.

-- 
Andrey

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Who can develop the following Python script into working application ?

2007-09-22 Thread Andrey Khavryuchenko

 DBR> And as you said yourself:

 DBR> """
 DBR> Frankly speaking I would prefer to pay for your kind assistance
 DBR> as it may take me to much time to learn some Python and understand the
 DBR> following script.
 DBR> """

 DBR> Now, again: http://www.guru.com/ There you can get devlopers for
 DBR> money. So what again is your problem?

Actually, I am a python (and django) developer, looking for a contract,
owning Nokia 770 and contacted original poster with no response.

-- 
Andrey V Khavryuchenko   http://a.khavr.com/
Chytach - unflood your feeds http://www.chytach.com/
Software Development Company http://www.kds.com.ua/
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] Py2Py 0.0.1 - python code reformatter, initial dev release

2007-01-15 Thread Andrey Khavryuchenko
Folks,

We release development preview snapshot of Py2Py code reformatter [1].

It is a byproduct of the PyBeast project aimed to create the python
mutation tester.

Now Py2Py code reformatter ignores all comments and 80-char line length
requirement. Nevertheless, it produces the same AST as the original code.

The code is developed in a test-first manner and has 100% test coverage.

Feedback, criticism and bug reports are welcome.

Links: 
[1] http://trac.kds.com.ua/project/pybeast/  
[2] http://www.kds.com.ua/wp/2007/01/16/py2py-001-initial-development-snapshot/

-- 
Andrey V Khavryuchenko
Software Development Company http://www.kds.com.ua/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: html + javascript automations = [mechanize + ?? ] or something else?

2007-01-16 Thread Andrey Khavryuchenko
John,

"J" == John  wrote:

 J> I have to write a spyder for a webpage that uses html + javascript. I
 J> had it written using mechanize but the authors of the webpage now use a
 J> lot of javascript. Mechanize can no longer do the job.  Does anyone
 J> know how I could automate my spyder to understand javascript? Is there
 J> a way to control a browser like firefox from python itself? How about
 J> IE?  That way, we do not have to go thru something like mechanize?

Up to my knowledge, there no way to test javascript but to fire up a
browser.

So, you might check Selenium (http://www.openqa.org/selenium/) and its
python module.

-- 
Andrey V Khavryuchenko
Software Development Company http://www.kds.com.ua/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: html + javascript automations = [mechanize + ?? ] or something else?

2007-01-16 Thread Andrey Khavryuchenko
Diez,

"DBR" == Diez B Roggisch wrote:

 >> Up to my knowledge, there no way to test javascript but to fire up a
 >> browser.
 >> 
 >> So, you might check Selenium (http://www.openqa.org/selenium/) and its
 >> python module.

 DBR> No use in that, as to be remote-controlled by python, selenium must be run
 DBR> on the server-site itself, due to JS security model restrictions.

Sorry, missed 'spider' word in the original post.

-- 
Andrey V Khavryuchenko
Software Development Company http://www.kds.com.ua/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Web Frameworks

2007-01-17 Thread Andrey Khavryuchenko
Shortash,

"S" == Shortash  wrote:

 S> I want to build a Python web app but im not sure which one to go for. I
 S> prefer something like asp.Net , which would allow me to fully seperate
 S> the presentation layer from the logic. Please advise?

Django?  http://www.djangoproject.com

-- 
Andrey V Khavryuchenko
Software Development Company http://www.kds.com.ua/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where to host a (Python) project?

2009-01-31 Thread Andrey Demidov

I use Google Code.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ping monitor - monitor ip in the background?

2008-11-02 Thread Andrey Balaguta
Hi, ScottZ.

I I have to write such a thing, I'll wrap the whole thing into some
class, say Pinger. It will have "do" method, which will perform one
particular pinging action. It'll also have a start/stop mechanism,
which will start a thread to continuously pinging a host. To notify
environment (say, yours tray icon) about host state change (dead/
alive), it will have callback mechanism (register_callback/
unregister_callback). Here, I've written a simple implementation,
maybe this will be helpful.

== pinger.py 
import os
import threading
import subprocess
import re
import time

class Pinger:
  def __init__(self, ip = None):
self.ip = None
self.running = False
self.callbacks = list()
self.setAddress(ip)
  def setAddress(self, ip):
if self.ip != ip:
  if self.running:
self.stop()
  self.ip = ip
  def do(self):
if os.name == "nt":  # Windows
pcmd = "ping -n 1 -w 1000 "
else:# *nix
pcmd = "ping -c1 -W1 "
p = subprocess.Popen(pcmd + self.ip, shell=True,
  stdout=subprocess.PIPE)
# give it time to respond
p.wait()
a = re.search('(.*)ms', p.stdout.read())
if a:
return True
else:
return False
  def start(self):
def run():
  result = False
  while self.running:
next = self.do()
if next != result and self.running:
  [ callback(next) for callback in self.callbacks ]
result = next
self.ping_thread = threading.Thread(target = run)
self.running = True
self.ping_thread.start()
  def stop(self):
self.running = False
  def register_callback(self, callback):
if callback not in self.callbacks:
  self.callbacks.append(callback)
  def unregister_callback(self, callback):
if callback in self.callbacks:
  self.callbacks.remove(callback)

if __name__ == '__main__':
   p = Pinger('192.168.1.1')
   def printout(alive):
if alive:
  print 'Host is alive.'
else:
  print 'Host is dead.'
   p.register_callback(printout)
   p.start()
   while True:
 print "Ding..."
 time.sleep(1)

====

Note that printout will be called ONLY if host state has changed, not
on EVERY ping.

--
Best Regards, Andrey Balaguta
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ping monitor - monitor ip in the background?

2008-11-02 Thread Andrey Balaguta
On Nov 2, 12:47 pm, "ScottZ" <[EMAIL PROTECTED]> wrote:
> Andrey - Thank you very much for the example.
> Is something missing after the def start(self): or should def run(): not
> be there?

No, Scott, this is one of the neatest features of Python -- "run" is a
nested function. It is visible and usable only in "start" function.

--
Best Regards, Andrey Balaguta
--
http://mail.python.org/mailman/listinfo/python-list


XMLRPC - persistent object state on server

2009-04-10 Thread Demidov Andrey
Hi, all

I need a XMLRPC server, which works with database and returns data to
the clients.
But I can not find any possibility to keep the object state on server
between the clients calls.

Here is my code:

  1. Server:

from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler

# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)

# Create server
server = SimpleXMLRPCServer(("localhost", 8000),
requestHandler=RequestHandler)
server.register_introspection_functions()

class MyClass:
def __init__(self, a):
self.a = a
# and some heavy works which I would like to do once
def say(self):
return a

cl = MyClass(100)

def return_my_value():
return cl.say()

server.register_function(return_my_value, 'r_v')

# Run the server's main loop
server.serve_forever()

   2. Client:

import xmlrpclib

s = xmlrpclib.ServerProxy('http://localhost:8000')
print s.r_v()

When I'm running client I get this error message:

de...@myhost ~/sources/study/python $ python rpc_client.py
Traceback (most recent call last):
  File "rpc_client.py", line 4, in 
print s.r_v()
  File "/usr/lib/python2.6/xmlrpclib.py", line 1199, in __call__
return self.__send(self.__name, args)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1489, in __request
verbose=self.__verbose
  File "/usr/lib/python2.6/xmlrpclib.py", line 1253, in request
return self._parse_response(h.getfile(), sock)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1392, in _parse_response
return u.close()
  File "/usr/lib/python2.6/xmlrpclib.py", line 838, in close
raise Fault(**self._stack[0])
xmlrpclib.Fault: :global name 'a' is
not defined">


How can I fix it?  Is there any possibility to keep the object state between
the clients calls?

Thanks,
Demas
--
http://mail.python.org/mailman/listinfo/python-list


Re: XMLRPC - persistent object state on server

2009-04-10 Thread Demidov Andrey
Thank you.
Of course, it is my stupid mistake.

Change:
>  def say(self):
>  return a
>
> to:
>  def say(self):
>  return self.a
>
> Cheers,
> Brian
>
--
http://mail.python.org/mailman/listinfo/python-list


How different are a generator's send and next methods

2009-09-30 Thread Andrey Fedorov
As far as I can tell, a generator's .next() is equivalent to .send(None). Is
this true?
If so, aren't they unified in a method with a single argument which defaults
to None?
- Andrey
-- 
http://mail.python.org/mailman/listinfo/python-list


Checking if a function invocation will throw a TypeError?

2009-10-29 Thread Andrey Fedorov
Is there a standard function that will check whether certain *args, and
**kwargs satisfy a argspec of a function (s.t. it does not throw a
TypeError). Say:

def foo(a,b=1):
pass

check(foo, 1,2) # True
check(foo, 1) # True
check(foo) # False
check(foo, 1, a=2) # False

Cheers,
Andrey
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking if a function invocation will throw a TypeError?

2009-10-29 Thread Andrey Fedorov
Will do, thanks. Doing it to make a @curry decorator, which only executes a
function once enough arguments have been passed in.

- Andrey

On Thu, Oct 29, 2009 at 6:53 PM, Chris Rebert  wrote:

> On Thu, Oct 29, 2009 at 11:43 AM, Andrey Fedorov 
> wrote:
> > Is there a standard function that will check whether certain *args, and
> > **kwargs satisfy a argspec of a function (s.t. it does not throw a
> > TypeError). Say:
> >
> > def foo(a,b=1):
> > pass
> >
> > check(foo, 1,2) # True
> > check(foo, 1) # True
> > check(foo) # False
> > check(foo, 1, a=2) # False
>
> Not that I know of, but you can write one yourself using
> inspect.getargspec():
> http://docs.python.org/library/inspect.html#inspect.getargspec
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Constraints on __sub__, __eq__, etc.

2010-02-18 Thread Andrey Fedorov
It seems intuitive to me that the magic methods for overriding the +, -, <,
==, >, etc. operators should have no sideffects on their operands. Also,
that == should be commutative and transitive, that > and < should be
transitive, and anti-commutative.

Is this intuition written up in a PEP, or assumed to follow from the
mathematical meanings?

- Andrey
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Constraints on __sub__, __eq__, etc.

2010-02-18 Thread Andrey Fedorov
>
> It may be intuitive to you, but its not true, written down anywhere, nor
> assumed by the language, and the mathematical meaning of the operators
> doesn't matter to Python. Python purposefully does not enforce anything for
> these methods.


Right, so neither is anything in PEP-8, but it's still considered "good
practice". I'm running across examples like you gave (__sub__ having a
side-effect on the left-hand operand) in some code, and am trying to find
concrete justification for avoiding it.

- Andrey

On Thu, Feb 18, 2010 at 11:28 AM, Stephen Hansen wrote:

> On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov wrote:
>
>> It seems intuitive to me that the magic methods for overriding the +, -,
>> <, ==, >, etc. operators should have no sideffects on their operands. Also,
>> that == should be commutative and transitive, that > and < should be
>> transitive, and anti-commutative.
>>
>> Is this intuition written up in a PEP, or assumed to follow from the
>> mathematical meanings?
>>
>
> It may be intuitive to you, but its not true, written down anywhere, nor
> assumed by the language, and the mathematical meaning of the operators
> doesn't matter to Python. Python purposefully does not enforce anything for
> these methods. Consider:
>
> >>> class Test(object):
> ... def __init__(self, v):
> ... self.v = v
> ... def __add__(self, other):
> ... self.v = self.v + other
> ... return "Ow!"
> ...
> >>> t = Test(5)
> >>> t + 2
> 'Ow!'
> >>> t.v
> 7
>
> It not only alters an operand, but its not even returning a meaningful
> result. This can be abused, but is also useful for certain uses.
>
> --S
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Bypassing properties on an object (also with __slots__?)

2010-02-18 Thread Andrey Fedorov
Two questions:

1 - is it documented that o.__dict__[attr] is a reliable way to bypass
property methods?
2 - can one bypass a property method if the class has __slots__?

Reason: I have a couple of different flavors of request objects which I need
to make lazily conform to a standard interface. As a simplified example,

a_foo_request = { 'ip': '1.2.3.4' }
a_bar_request = { 'my-ip': b'\x01\x02\x03\x04' }


My solution is to create two classes:

class FooRequest(dict):
@property
def ip(self):
return self['ip']

class BarRequest(dict):
@property
def ip(self):
return "%i.%i.%i.%i" % struct.unpack("4B", self['my-ip'])


Then:

FooRequest(a_foo_request).ip == '1.2.3.4'

# and
req = BarRequest(a_bar_request)
req.ip == '1.2.3.4'

But some of these getters are CPU-intensive, and since the extended objects
always remain immutable, I memoize them in req.__dict__, like:

class BarRequest(dict):
@property
def ip(self):
if 'ip' in self.__dict__:
return self.__dict__['ip']
else:
self.__dict__['ip'] = "%i.%i.%i.%i" % struct.unpack("4B",
self['my-ip'])
return self.__dict__['ip']


Which works as intended, and (I think) can be made prettier with a custom
constant_property decorator. So...

Question 0: Is there an obvious better way of achieving this functionality?
Question 1: Is it safe to rely on __dict__ to bypass properties this way?
Question 2: I'd like to use __slots__, but I can't seem to find a way to
stop the property method from recursing. Is there one?

Cheers,
Andrey
-- 
http://mail.python.org/mailman/listinfo/python-list


Chaining 501 generators breaks everything?

2010-02-19 Thread Andrey Fedorov
I implemented a Sieve of
Eratosthenes<http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes>primes
algorithm using generators:

http://gist.github.com/309109


This code which chains together 500 generators works fine (~1/20th of a
second) on my laptop. The code which chaines 501 generators (s/498/499/ on
line 23) doesn't seem to finish.

Does anyone know the reason for this, or can anyone point me where to look
for a good explanation?

Cheers,
Andrey
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Chaining 501 generators breaks everything?

2010-02-19 Thread Andrey Fedorov
Ack, just ran it from shell, realized my editor was just choking on a
"maximum recursion depth exceeded" RuntimeError. Didn't realize generators
used the call stack...

- Andrey

On Fri, Feb 19, 2010 at 2:47 PM, Andrey Fedorov  wrote:

> I implemented a Sieve of 
> Eratosthenes<http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes>primes 
> algorithm using generators:
>
> http://gist.github.com/309109
>
>
> This code which chains together 500 generators works fine (~1/20th of a
> second) on my laptop. The code which chaines 501 generators (s/498/499/ on
> line 23) doesn't seem to finish.
>
> Does anyone know the reason for this, or can anyone point me where to look
> for a good explanation?
>
> Cheers,
> Andrey
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Don't work __getattr__ with __add__

2010-03-04 Thread Andrey Simurzin
On 4 мар, 11:38, Chris Rebert  wrote:
> On Thu, Mar 4, 2010 at 12:25 AM, Андрей Симурзин  wrote:
> > It is object of the class A, in conteiner's class tmpA. Not all method
> > from A are in the tmpA. So for exapmle:
> > A + B -- yes , tmpA + B no. I try to call method from A for tmpA. I
> > can to call simple method,  such as change(), bit __add__ -  don't
> > work. If to remove inheritance from object, the code work's. Help me,
> > please
>
> Some clarity has been lost in translation, but I think I get what you're 
> saying.
> __add__ and the other double-underscore special methods are not looked
> up using __getattr__ or __getattribute__, hence trying to do addition
> on tmpA, which does not define an __add__ method, fails.
>
> For a full explanation, 
> read:http://docs.python.org/reference/datamodel.html#special-method-lookup...
>
> Cheers,
> Chris
> --http://blog.rebertia.com

Thank you very much
-- 
http://mail.python.org/mailman/listinfo/python-list


Down casting Python objects

2010-03-09 Thread Andrey Fedorov
So I have `x', a instance of class `Foo'. I also have class `Bar', a class
extending `Foo' with a couple of methods. I'd like to "down cast" x as
efficiently as possible. Is it OK to just set `x.__class__ = Bar' and expect
things to work OK in all major versions of CPython?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Down casting Python objects

2010-03-10 Thread Andrey Fedorov
On Wed, Mar 10, 2010 at 12:24 AM, Rami Chowdhury 
wrote:

> Could you tell us *why* you need to down-cast x? Explicit type-casting is
> usually unnecessary in Python...


Sure! It's related to the longer question I unwisely asked during PyCon [1]
(when no one had time to read it, I suppose).

I have a couple of different flavors of request objects which I'd like to
make conform to a single interface. So Request `x' come in, I determine
which kind of request I'm dealing with, and would like to "down-cast" it to
ARequest or BRequest, classes which will provide appropriate accessor
properties for the rest of the code to use.

An option clearly in line with Python's docs might be for `x' to be an
attribute of an ARequest instance, but that would complicate the code of
ARequest. What I'm looking for is a way of adding mix-in's at runtime, if
that makes sense.

Cheers,
Andrey

1. http://mail.python.org/pipermail/python-list/2010-February/1236681.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Repetition of work in Jython

2010-03-25 Thread Andrey Fedorov
Hi all,

So from what I understand, Jython translates Python code into JVM byte code.
Does anyone know why this was chosen instead of translating Python bytecode
to JVM bytecode directly? It seems that it would be a lot easier to get
Jython up-to-speed if there could be some "shared components" between them
and CPython, no?

- Andrey
-- 
http://mail.python.org/mailman/listinfo/python-list


Function to apply superset of arguments to a function

2009-09-09 Thread Andrey Fedorov
Hi all,

I've written a function [1] called apply_some which takes a set of
keywords arguments, filters only those a function is expecting, and
calls the function with only those arguments. This is meant to
suppress TypeErrors - a way to abstract the logic which checks what
arguments a passed-in function accepts.

For example:

> def foo(x=1, y=2):
>return (x,y)
>
> apply_some(foo, y=0, z="hi") // calls foo(y=0)
> -> (1,0)

I'd like to expand this to fill undefined arguments with None, but
before I do, does anyone know of any packages/libraries which either
do something similar or would make this code cleaner?

Cheers,
Andrey

1. http://gist.github.com/183375
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function to apply superset of arguments to a function

2009-09-09 Thread Andrey Fedorov
When a web request is made, my Django views are called with argument
`user_id' present if someone is logged in, and set to None if the request is
anonymous. The response varies based on this argument - someone pulling a
team's information will get their relationship to the team if they are
logged in, but not if they are anonymous.

I'd like the views to remain agnostic to this functionality, because most of
them don't care if a particular user is calling them. Hence, I don't want to
include `user_id=None' in all of their definitions. However, to support the
views that *do* differentiate based on user, and to minimize effort required
to go from being user-agnostic to user-specific, I'd like my authentication
mechanism to pass `user_id' (among other things) only if they are present.

I suppose this is an IoC principle or something - where methods declare what
information they need in their argument list. Another example of this
application is in accepting POST variables - I use a decorator @acceptsPOST
which uses `apply_some' to pass all POST variables into a view, and let it
ignore the ones it doesn't need. For example:

@acceptsPOST
> def login(request, user_name, password):
>...
>

Instead of:

def login(request):
> user_name = request.POST['user_name'] if 'user_name' in request.POST
> else None
> password = request.POST['password'] if 'password' in request.POST else
> None
> ...
>

This is especially useful both when adding/removing POST variables, and when
there end up being a lot of them.

Cheers,
Andrey


On Wed, Sep 9, 2009 at 1:40 PM, David Stanek  wrote:

> On Wed, Sep 9, 2009 at 12:45 PM, Andrey Fedorov
> wrote:
> > Hi all,
> >
> > I've written a function [1] called apply_some which takes a set of
> > keywords arguments, filters only those a function is expecting, and
> > calls the function with only those arguments. This is meant to
> > suppress TypeErrors - a way to abstract the logic which checks what
> > arguments a passed-in function accepts.
> >
> > For example:
> >
> >> def foo(x=1, y=2):
> >>return (x,y)
> >>
> >> apply_some(foo, y=0, z="hi") // calls foo(y=0)
> >> -> (1,0)
> >
> > I'd like to expand this to fill undefined arguments with None, but
> > before I do, does anyone know of any packages/libraries which either
> > do something similar or would make this code cleaner?
> >
> > Cheers,
> > Andrey
> >
> > 1. http://gist.github.com/183375
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
> What is your use-case for using this? It seems really odd to me.
>
> --
> David
> blog: http://www.traceback.org
> twitter: http://twitter.com/dstanek
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Wheezy.web - is it been developed?

2014-02-18 Thread Marcio Andrey Oliveira
Hi.

I stumbled upon Wheezy.web and I got interested into learn more about it.

After googling I didn't find that many information about it: only docs and
samples from its web site.

I didn't find a mailing list nor user groups and no tutorials from its
users.

Is Wheezy.web been actively developed? Does it have any user base community
that I could get in touch with? Or should I forget about it and stick to
say flask or pyramid?

Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wheezy.web - is it been developed?

2014-02-19 Thread Marcio Andrey Oliveira
Hi.

Thanks for replying.

I navigated in its site. I just feel strange that no one wrote tutorials of
it (not counting some speed testing) and that there is no Wheezy.web
community (yet).

I'll give it a try and for sure I'll get in touch in case of problems.

Thank you.


2014-02-19 4:18 GMT-03:00 Andriy Kornatskyy :

> Marcio,
>
> The wheezy.web framework (http://bitbucket.org/akorn/wheezy.web) supplies
> documentation, tutorials, quick starts and benchmark for you. Due to
> modular architecture, it is being developed in several independent loosely
> coupled libraries under wheezy.*. The source code is easy to read, there is
> 100% test coverage.
>
> No bells and whistles.
>
> I believe the web framework should not be something cryptic (requiring
> community to exchange ideas about workarounds) nor something that involves
> infinitive development cycle.
>
> If you have any questions I will be happy to answer in this mailing list
> or personally.
>
> Thanks.
>
> Andriy Kornatskyy
>
> On Feb 19, 2014, at 1:48 AM, Marcio Andrey Oliveira 
> wrote:
>
> > Hi.
> >
> > I stumbled upon Wheezy.web and I got interested into learn more about it.
> >
> > After googling I didn't find that many information about it: only docs
> and samples from its web site.
> >
> > I didn't find a mailing list nor user groups and no tutorials from its
> users.
> >
> > Is Wheezy.web been actively developed? Does it have any user base
> community that I could get in touch with? Or should I forget about it and
> stick to say flask or pyramid?
> >
> > Thank you.
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 


*Do you have an arcade site? I do 1:1 Game Exchange *
*Play free on-line games
<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*

*Get free games for*

<http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wheezy.web - is it been developed?

2014-02-19 Thread Marcio Andrey Oliveira
To say the truth right now I'm studying some frameworks (not only in
Python) to get one I feel more comfortable with.

I'm learning Flask too and it seems a very nice project.

And I completely agree with you that the bigger the community the easier is
to get support.

Regards.


2014-02-19 9:01 GMT-03:00 Chris "Kwpolska" Warrick :

> On Wed, Feb 19, 2014 at 8:18 AM, Andriy Kornatskyy
>  wrote:
> > I believe the web framework should not be something cryptic (requiring
> community to exchange ideas about workarounds) nor something that involves
> infinitive development cycle.
>
> Having lots of humans give support is much better when you have
> problems.  You are more likely to get a quick response from a big
> group of humans than from one developer.
>
> On Wed, Feb 19, 2014 at 12:31 PM, Marcio Andrey Oliveira
>  wrote:
> > I navigated in its site. I just feel strange that no one wrote tutorials
> of it (not counting some speed testing) and that there is no Wheezy.web
> community (yet).
>
> I personally suggest trying something more popular, like Flask,
> Bottle, Pyramid, or Django (though it's quite big and complicated).
> Lots of tutorials exist for those.  There are big, vivid communities
> offering help and support.  You can often find good solutions for
> popular problems (like user accounts) without reinventing wheels.
> Flask is the easiest option, and it's very popular.
>
> --
> Chris "Kwpolska" Warrick <http://kwpolska.tk>
> PGP: 5EAAEA16
> stop html mail | always bottom-post | only UTF-8 makes sense
>



-- 


*Do you have an arcade site? I do 1:1 Game Exchange *
*Play free on-line games
<http://plicatibu.com/?utm_source=plicatibu&utm_medium=email&utm_content=gmail&utm_campaign=Signature>*

*Get free games for*

<http://plicatibu.com/mkand0> <http://plicatibu.com/mkbb0>
-- 
https://mail.python.org/mailman/listinfo/python-list