Translation of Python!

2014-06-30 Thread Doriven Basha
Hello everybody!
I want to translate python into albanian language because it's very flexible 
and similar to english words used in programming.Can anybody help me to start 
translation of the python the programm used or anything else to get started 
with programming translation???I can do it by myself but i want the road how to 
do it???Please help me !
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Translation of Python!

2014-06-30 Thread INADA Naoki
Do you mean translating official document?

We are translating docs into Japanese using Transifex.
https://www.transifex.com/projects/p/python-33-ja/

But I hope PSF have official project on Transifex.

On Mon, Jun 30, 2014 at 4:24 PM, Doriven Basha  wrote:
> Hello everybody!
> I want to translate python into albanian language because it's very flexible 
> and similar to english words used in programming.Can anybody help me to start 
> translation of the python the programm used or anything else to get started 
> with programming translation???I can do it by myself but i want the road how 
> to do it???Please help me !
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
INADA Naoki  
-- 
https://mail.python.org/mailman/listinfo/python-list


[Q] override __init__() method of classes implemented in C

2014-06-30 Thread Makoto Kuwata
Is it impossible to override __init__() method of classes
implemented in C (such as datetime.datetime) ?


example.py:

from datetime import datetime
 class Foo(datetime):
def __init__(self):
pass
 obj = Foo()


Result (Python 2.7.7 and 3.4.1):

Traceback (most recent call last):
  File "hoge.py", line 7, in 
obj = Foo()
TypeError: Required argument 'year' (pos 1) not found


It seems to be failed to override datetime.__init__() in subclass.


--
regards,
makoto kuwata
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Q] override __init__() method of classes implemented in C

2014-06-30 Thread Chris Angelico
On Mon, Jun 30, 2014 at 5:45 PM, Makoto Kuwata  wrote:
> Result (Python 2.7.7 and 3.4.1):
>
> Traceback (most recent call last):
>  File "hoge.py", line 7, in 
>obj = Foo()
> TypeError: Required argument 'year' (pos 1) not found
>
>
> It seems to be failed to override datetime.__init__() in subclass.
>

Actually, __init__ isn't the problem here, __new__ is.

class Foo(datetime):
def __new__(self):
return super().__new__(self,2014,1,1)

>>> Foo()
Foo(2014, 1, 1, 0, 0)

Maybe that helps, maybe it doesn't, but the issue you're seeing is
specific to that class.

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


Re: [Q] override __init__() method of classes implemented in C

2014-06-30 Thread Makoto Kuwata
On Mon, Jun 30, 2014 at 4:52 PM, Chris Angelico  wrote:

>
> Actually, __init__ isn't the problem here, __new__ is.
>
> class Foo(datetime):
> def __new__(self):
> return super().__new__(self,2014,1,1)
>
> >>> Foo()
> Foo(2014, 1, 1, 0, 0)
>
> Maybe that helps, maybe it doesn't, but the issue you're seeing is
> specific to that class.
>

Got it! Thank you!

--
regards,
makoto kuwata
-- 
https://mail.python.org/mailman/listinfo/python-list


Python While loop Takes too much time.

2014-06-30 Thread Jaydeep Patil
I have did excel automation using python.
In my code I am creating python dictionaries for different three columns data 
at a time.There are are many rows above 4000. Lets have look in below function. 
Why it is taking too much time?

Code:

def transientTestDict(self,ws,startrow,startcol):

self.hwaDict = OrderedDict()
self.yawRateDict = OrderedDict()

rng = ws.Cells(startrow,startcol)

while not rng.Value is None:
r = rng.Row
c = rng.Column

time = rng.Value

rng1 = rng.GetOffset(0,1)
hwa = rng1.Value

rng2 = rng.GetOffset(0,2)
yawrate = rng2.Value

self.hwaDict[time] = hwa,rng.Row,rng.Column
self.yawRateDict[time] = yawrate,rng.Row,rng.Column

rng = ws.Cells(r+1,c)



Please have look in above code & suggest me to improve speed of my code.



Regards
Jaydeep Patil
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python While loop Takes too much time.

2014-06-30 Thread Peter Otten
Jaydeep Patil wrote:

> I have did excel automation using python.
> In my code I am creating python dictionaries for different three columns
> data at a time.There are are many rows above 4000. Lets have look in below
> function. Why it is taking too much time?
> 
> Code:
> 
> def transientTestDict(self,ws,startrow,startcol):
> 
> self.hwaDict = OrderedDict()
> self.yawRateDict = OrderedDict()
> 
> rng = ws.Cells(startrow,startcol)
> 
> while not rng.Value is None:
> r = rng.Row
> c = rng.Column
> 
> time = rng.Value
> 
> rng1 = rng.GetOffset(0,1)
> hwa = rng1.Value
> 
> rng2 = rng.GetOffset(0,2)
> yawrate = rng2.Value
> 
> self.hwaDict[time] = hwa,rng.Row,rng.Column
> self.yawRateDict[time] = yawrate,rng.Row,rng.Column
> 
> rng = ws.Cells(r+1,c)
> 
> 
> 
> Please have look in above code & suggest me to improve speed of my code.

Assuming that what slows down things is neither Python nor Excel, but the 
communication between these I'd try to do as much as possible in Python. For 
example (untested):

def transientTestDict(self, ws, startrow, startcol):
self.hwaDict = OrderedDict()
self.yawRateDict = OrderedDict()

time_col, hwa_col, yawrate_col = range(startcol, startcol+3)

for row in xrange(startrow, sys.maxint):
time = ws.Cells(row, time_col).Value
if time is None:
break
hwa = ws.Cells(row, hwa_col).Value
yawrate = ws.Cells(row, yawrate_col).Value

self.hwaDict[time] = hwa, row, time_col
self.yawRateDict[time] = yawrate, row, time_col

While this avoids cell arithmetic in Excel it still fetches every value 
separately, so I have no idea if there is a significant effect.

Does Excel provide a means to get multiple cell values at once? That would 
likely help.


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


Re: [OT] What can Nuitka do?

2014-06-30 Thread Michael Torrie
On 06/28/2014 09:16 AM, Chris Angelico wrote:
>> I remember approx. 10 years ago a neighboring dept. at my work effectively
>> killed our 10 MB/s Ethernet segment with such traffic (due to a
>> misconfigured switch/router?). Running an ethernet analyzer showed a single
>> X11 host-server session occupied ~80% bandwidth.  AFAICR, it was a Sun
>> workstation.
>> A real PITA.
> 
> Either that was a horribly inefficient X11 connection (as mine was -
> the virtual machine sent basically a constantly-updated bitmapped
> image to rdesktop, which then couldn't do anything more efficient than
> feed that image to the X server), or something was horribly
> misconfigured. I've frequently done much more reasonable X11
> forwarding, with high success and low traffic;

Only the most primitive X11 apps are at all fast over network
forwarding.  If the app uses any modern toolkit, then it's basically
just sending a bunch of bitmaps over the wire (changes), which would be
fine, but X11 involves a lot of server round trips.  Forwarding works
fine over SSH on a LAN (compression with -X helps too), but anything
slower than that is very nearly unusable.  I used to run XEmacs over a
modem (I know; I just preferred it to Emacs and I didn't know ViM), and
it worked great with server-side drawing and fonts, as X11 was designed
to do 90s-style.  But now if I need to run X11 apps over a slower link
these days I use OpenNX which dramatically helps by eliminating round
trips, and applying bitmap compression.  But the fact remains X11 kind
of sucks these days, and "network transparency" now basically means a
slightly suckier version of VNC in effect.  RDP protocol is actually
much more efficient than X11 forwarding with modern apps.  So your
rdesktop example is actually not a horribly inefficient X11 connection,
other than the fact that X11 is inefficient.  Honestly once Wayland has
per-app RDP built into it, there'll be no reason at all to cheer for X11.

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


Re: [OT] What can Nuitka do?

2014-06-30 Thread Chris Angelico
On Mon, Jun 30, 2014 at 11:10 PM, Michael Torrie  wrote:
> Only the most primitive X11 apps are at all fast over network
> forwarding.  If the app uses any modern toolkit, then it's basically
> just sending a bunch of bitmaps over the wire (changes), which would be
> fine, but X11 involves a lot of server round trips.  Forwarding works
> fine over SSH on a LAN (compression with -X helps too), but anything
> slower than that is very nearly unusable.  I used to run XEmacs over a
> modem (I know; I just preferred it to Emacs and I didn't know ViM), and
> it worked great with server-side drawing and fonts, as X11 was designed
> to do 90s-style.  But now if I need to run X11 apps over a slower link
> these days I use OpenNX which dramatically helps by eliminating round
> trips, and applying bitmap compression.  But the fact remains X11 kind
> of sucks these days, and "network transparency" now basically means a
> slightly suckier version of VNC in effect.  RDP protocol is actually
> much more efficient than X11 forwarding with modern apps.  So your
> rdesktop example is actually not a horribly inefficient X11 connection,
> other than the fact that X11 is inefficient.  Honestly once Wayland has
> per-app RDP built into it, there'll be no reason at all to cheer for X11.

Hmm. I'm not sure that it's necessarily that bad; I've done 3G-based
X11 forwarding fairly successfully on occasion. Yes, it's potentially
quite slow, but it certainly works - I've used SciTE, for instance,
and I've used some GTK2 apps without problems. What do you mean by
"modern toolkit"?

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


Creating a dict-like class that counts successful and failed key matches

2014-06-30 Thread python
As a diagnostic tool, I would like to create a dict-like class
that counts successful and failed key matches by key. By failed
I mean in the sense that a default value was returned vs. an
exception raised. By count, I mean by tracking counts for
individual keys vs. just total success/failure counts. The
class needs to support setting values, retrieving values, and
retrieving keys, items, and key/item pairs. Basically anything
that a regular dict, I'd like my modified class to do as well.
Use case: I'm curious to see what key's we're missing that our
code is using default to provide and I'm also interested in
looking at our high frequency keys as a way to double check our
processes.
Is this a common pattern covered by the standard lib (I don't
see anything in collections)?
I'm looking for ideas on how to implement ... as a subclass of
Dict, as a duck-like class offering Dict like methods, other?
I'm also looking for some hints on what magic methods I should
override to accomplish my goal, eg. beyond __getitem__.
Thank you,
Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a dict-like class that counts successful and failed key matches

2014-06-30 Thread python
After some additional research, it looks like I may have even
more options to consider including using a UserDict mixin.



I think I've identified another magic method to subclass ...
__missing__.





- Original message -

From: [1]pyt...@bdurham.com

To: [2]python-list@python.org

Subject: Creating a dict-like class that counts successful and
failed key matches

Date: Mon, 30 Jun 2014 09:43:49 -0400



As a diagnostic tool, I would like to create a dict-like class
that counts successful and failed key matches by key. By failed
I mean in the sense that a default value was returned vs. an
exception raised. By count, I mean by tracking counts for
individual keys vs. just total success/failure counts. The
class needs to support setting values, retrieving values, and
retrieving keys, items, and key/item pairs. Basically anything
that a regular dict, I'd like my modified class to do as well.



Use case: I'm curious to see what key's we're missing that our
code is using default to provide and I'm also interested in
looking at our high frequency keys as a way to double check our
processes.



Is this a common pattern covered by the standard lib (I don't
see anything in collections)?



I'm looking for ideas on how to implement ... as a subclass of
Dict, as a duck-like class offering Dict like methods, other?



I'm also looking for some hints on what magic methods I should
override to accomplish my goal, eg. beyond __getitem__.



Thank you,

Malcolm



--

[3]https://mail.python.org/mailman/listinfo/python-list

References

1. mailto:pyt...@bdurham.com
2. mailto:python-list@python.org
3. https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a dict-like class that counts successful and failed key matches

2014-06-30 Thread Chris Angelico
On Mon, Jun 30, 2014 at 11:43 PM,   wrote:
> As a diagnostic tool, I would like to create a dict-like class that counts
> successful and failed key matches by key. By failed I mean in the sense that
> a default value was returned vs. an exception raised. By count, I mean by
> tracking counts for individual keys vs. just total success/failure counts.
> The class needs to support setting values, retrieving values, and retrieving
> keys, items, and key/item pairs. Basically anything that a regular dict, I'd
> like my modified class to do as well.

Sounds like you want to subclass dict, then. Something like this:

class StatsDict(dict):
def __init__(self, *a, **ka):
super().__init__(*a, **ka)
self.success = defaultdict(int)
self.fail = defaultdict(int)
def __getitem__(self, item):
try:
ret = super().__getitem__(item)
self.success[item] += 1
return ret
except KeyError:
self.fail[item] += 1
raise

On initialization, set up some places for keeping track of stats. On
item retrieval (I presume you're not also looking for stats on item
assignment - for that, you'd want to also override __setitem__),
increment either the success marker or the fail marker for that key,
based exactly on what you say: was something returned, or was an
exception raised.

To get the stats, just look at the success and fail members:

>>> d = StatsDict()
>>> d["foo"]=1234
>>> d["foo"]
1234
>>> d["spam"]
(chomp)
KeyError: 'spam'
>>> d["foo"]
1234
>>> d["foo"]
1234
>>> d["test"]
(chomp)
KeyError: 'test'
>>> len(d.success) # Unique successful keys
1
>>> len(d.fail) # Unique failed keys
2
>>> sum(d.success.values()) # Total successful lookups
3
>>> sum(d.fail.values()) # Total unsuccessful lookups
2

You can also interrogate the actual defaultdicts, eg to find the hottest N keys.

For everything other than simple key retrieval, this should function
identically to a regular dict. Its repr will be a dict's repr, its
iteration will be its keys, all its other methods will be available
and won't be affected by this change. Notably, the .get() method isn't
logged; if you use that and want to get stats for it, you'll have to
reimplement it - something like this:

def get(self, k, d=None):
try:
return self[k]
except KeyError:
return d

The lookup self[k] handles the statisticking, but if you let this go
through to the dict implementation of get(), it seems to ignore
__getitem__.

This probably isn't exactly what you want, but it's a start, at least,
and something to tweak into submission :)

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


Re: Creating a dict-like class that counts successful and failed key matches

2014-06-30 Thread python
Hi Chris,

> Sounds like you want to subclass dict, then. Something like this:

Nice!!! 

I need to study your solution, but at first blush it looks exactly like
what I wanted to implement.

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


Re: Creating a dict-like class that counts successful and failed key matches

2014-06-30 Thread Ethan Furman

On 06/30/2014 07:44 AM, pyt...@bdurham.com wrote:


Nice!!!

I need to study your solution, but at first blush it looks exactly like
what I wanted to implement.


Keep in mind that dict /will not/ call your overridden methods, so if, for example, you provide your own __getitem__ you 
will also need to provide your own copies of any dict method that calls __getitem__.


--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a dict-like class that counts successful and failed key matches

2014-06-30 Thread python
Ethan,

> Keep in mind that dict /will not/ call your overridden methods, so if, for 
> example, you provide your own __getitem__ you 
will also need to provide your own copies of any dict method that calls
__getitem__.

I'm not sure I understand. Are you saying that Chris's __getitem__ will
not be called by other dict methods that would normally call this magic
method and instead call the parent's __getitem__ directly (via super()
or something similar?)?

Is this specific to the native Dict class (because its implemented in C
vs. Python?) or is this behavior more general.

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


Re: Creating a dict-like class that counts successful and failed key matches

2014-06-30 Thread Ethan Furman

On 06/30/2014 09:47 AM, pyt...@bdurham.com wrote:


Keep in mind that dict /will not/ call your overridden methods, so if,
for example, you provide your own __getitem__ you will also need to
provide your own copies of any dict method that calls __getitem__.


I'm not sure I understand. Are you saying that Chris's __getitem__ will
not be called by other dict methods that would normally call this magic
method and instead call the parent's __getitem__ directly (via super()
or something similar?)?


That is what I am saying.



Is this specific to the native Dict class (because its implemented in C
vs. Python?) or is this behavior more general.


I /think/ it's only dict, but I haven't played with subclassing lists, tuples, etc.  It's not a C vs Python issue, but a 
'implemented with __private methods' issue.  From what I have seen so far in the confusion and frustration that decision 
has caused, I do not think it was a good one.  :(


--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python While loop Takes too much time.

2014-06-30 Thread marco . nawijn
On Monday, June 30, 2014 1:32:23 PM UTC+2, Jaydeep Patil wrote:
> I have did excel automation using python.
> 
> In my code I am creating python dictionaries for different three columns data 
> at a time.There are are many rows above 4000. Lets have look in below 
> function. Why it is taking too much time?
> 
> 
> 
> Code:
> 
> 
> 
> def transientTestDict(self,ws,startrow,startcol):
> 
> 
> 
> self.hwaDict = OrderedDict()
> 
> self.yawRateDict = OrderedDict()
> 
> 
> 
> rng = ws.Cells(startrow,startcol)
> 
> 
> 
> while not rng.Value is None:
> 
> r = rng.Row
> 
> c = rng.Column
> 
> 
> 
> time = rng.Value
> 
> 
> 
> rng1 = rng.GetOffset(0,1)
> 
> hwa = rng1.Value
> 
> 
> 
> rng2 = rng.GetOffset(0,2)
> 
> yawrate = rng2.Value
> 
> 
> 
> self.hwaDict[time] = hwa,rng.Row,rng.Column
> 
> self.yawRateDict[time] = yawrate,rng.Row,rng.Column
> 
> 
> 
> rng = ws.Cells(r+1,c)
> 
> 
> 
> 
> 
> 
> 
> Please have look in above code & suggest me to improve speed of my code.
> 
> 
> 
> 
> 
> 
> 
> Regards
> 
> Jaydeep Patil

Hi Jaydeep,

I agree with Peter. I would avoid moving from cell to
cell through the EXCEL interface if you can avoid.

If possible, I would try to read ranges from EXCEL into
a python list (or maybe numpy arrays) and do the processing
in Python. In the past I even dumped an EXCEL sheet as a
CSV file and then used the numpy recfromcsv function to 
process the data.

If you are really brave, dump EXCEL alltogether :) and do
all the work in Python (have you already tried IPython 
notebook?).

Regards,

Marco

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


Re: Translation of Python!

2014-06-30 Thread Doriven Basha
I want to translate it into my language like the chinese python 
https://code.google.com/p/zhpy/w/list?q=label:Chinese
can you help me?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Translation of Python!

2014-06-30 Thread Doriven Basha
On Monday, June 30, 2014 8:37:43 PM UTC+2, Doriven Basha wrote:
> I want to translate it into my language like the chinese python 
> https://code.google.com/p/zhpy/w/list?q=label:Chinese
> 
> can you help me?

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


unorderable error: less ok, equal ok, less-or-equal gives unorderable error!

2014-06-30 Thread RainyDay
Hi, in python 3.4.1, I get this surpising behaviour:

>>> l=Loc(0,0)
>>> l2=Loc(1,1)
>>> l>l2
False
>>> l>> l<=l2
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unorderable types: Loc() <= Loc()
>>> l==l2
False
>>> lhttps://mail.python.org/mailman/listinfo/python-list


Re: Writing Multiple files at a times

2014-06-30 Thread subhabangalore
On Sunday, June 29, 2014 4:19:27 PM UTC+5:30, subhaba...@gmail.com wrote:
> Dear Group,
> 
> 
> 
> I am trying to crawl multiple URLs. As they are coming I want to write them 
> as string, as they are coming, preferably in a queue. 
> 
> 
> 
> If any one of the esteemed members of the group may kindly help.
> 
> 
> 
> Regards,
> 
> Subhabrata Banerjee.

Dear Group,

Thank you for your kind suggestion. But I am not being able to sort out,
"fp = open( "scraped/body{:0>5d}.htm".format( n ), "w" ) "
please suggest.

Regards,
Subhabrata Banerjee. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unorderable error: less ok, equal ok, less-or-equal gives unorderable error!

2014-06-30 Thread Peter Otten
RainyDay wrote:

> Hi, in python 3.4.1, I get this surpising behaviour:
> 
 l=Loc(0,0)
 l2=Loc(1,1)
 l>l2
> False
 l True
 l<=l2
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: unorderable types: Loc() <= Loc()
 l==l2
> False
 l True
> 
> Loc implements both __lt__ and __eq__, which should be enough (?),

These two methods should be sufficient if you use the 
functools.total_ordering class decorator, see

https://docs.python.org/dev/library/functools.html#functools.total_ordering

> but even after I've added __lte__, I still have the error.

There is no special method of that name; it should probably be __le__().

> 
> implementation:
> 
> class Loc:
> def __init__(self, x, y):
> self._loc = x, y
> self.x, self.y = x, y
> 
> def __eq__(self, other):
> return self._loc == getattr(other, "_loc", None)

Note that None is not a good default when _loc is expected to be a tuple:

>>> None < ()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unorderable types: NoneType() < tuple()

> 
> def __lt__(self, other):
> return self._loc < other._loc
> 
>  - andrei


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


Re: Creating a dict-like class that counts successful and failed key matches

2014-06-30 Thread python
Ethan,

>> Is this specific to the native Dict class (because its implemented in C vs. 
>> Python?) or is this behavior more general.

> I /think/ it's only dict, but I haven't played with subclassing lists, 
> tuples, etc.  It's not a C vs Python issue, but a 
'implemented with __private methods' issue.  From what I have seen so
far in the confusion and frustration that decision 
has caused, I do not think it was a good one.  :(

Thanks for the heads-up!

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


Writing files at run time

2014-06-30 Thread subhabangalore
Dear Group,

In my previous 
post["https://groups.google.com/forum/#!topic/comp.lang.python/ZYjsskV5MgE";] I 
was trying to discuss some issue on file writing. 

I got an associated issue. 

I am trying to crawl a link, through urllib and trying to store its results in 
different files. As discussed I could work out a solution for this and with 
your kind help trying to learn some new coding styles. 

Now, I am getting an associated issue. 

The crawler I am trying to construct would run daily-may be at a predefined 
time. 
[I am trying to set the parameter with "time" module]. 

Now, in the file(s) data are stored, are assigned or created at one time.

Data changes daily if I crawl daily newspapers. 

I generally change the name of the files with a sitting for few minutes before 
a run. But this may not be the way. 

I am thinking of a smarter solution. 

If anyone of the esteemed members may kindly show a hint, how the name of the 
storing files may be changed automatically as crawler runs every day, so that 
data may be written there and retrieved. 

Thanking you in advance,
Regards,
Subhabrata Banerjee. 
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Translation of Python!

2014-06-30 Thread Michael Torrie
On 06/30/2014 12:37 PM, Doriven Basha wrote:
> I want to translate it into my language like the chinese python
> https://code.google.com/p/zhpy/w/list?q=label:Chinese can you help
> me?

I don't understand chinese, so I am not sure what this web page is
about. Do you want to translate Python's messages (error tracebacks,
etc) into Romanian?  Or are you wanting to create a language that uses
Python syntax but with Romanian keywords replacing english ones like if,
else, while, def, etc?

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


Re: unorderable error: less ok, equal ok, less-or-equal gives unorderable error!

2014-06-30 Thread RainyDay
On Monday, June 30, 2014 3:34:25 PM UTC-4, Peter Otten wrote:
> RainyDay wrote:
> 
> 
> 
> > Hi, in python 3.4.1, I get this surpising behaviour:
> 
> > 
> 
>  l=Loc(0,0)
> 
>  l2=Loc(1,1)
> 
>  l>l2
> 
> > False
> 
>  l 
> > True
> 
>  l<=l2
> 
> > Traceback (most recent call last):
> 
> >   File "", line 1, in 
> 
> > TypeError: unorderable types: Loc() <= Loc()
> 
>  l==l2
> 
> > False
> 
>  l 
> > True
> 
> > 
> 
> > Loc implements both __lt__ and __eq__, which should be enough (?),
> 
> 
> 
> These two methods should be sufficient if you use the 
> 
> functools.total_ordering class decorator, see


Thanks! I literally failed to read one more paragraph in a SO answer
which referenced this decorator. I really need to start reading those
paragraphs, they often provide answers...

> > but even after I've added __lte__, I still have the error.
> 
> 
> 
> There is no special method of that name; it should probably be __le__().


Right, I used lte in django and assumed they were consistent with python.
 
> > def __eq__(self, other):
> 
> > return self._loc == getattr(other, "_loc", None)
> 
> 
> 
> Note that None is not a good default when _loc is expected to be a tuple:
> 

I'm only using None in equality comparison, it's never a default value of
_loc itself, so this should be ok because it'll compare to all other object
types and correctly say they're unequal.

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


Re: unorderable error: less ok, equal ok, less-or-equal gives unorderable error!

2014-06-30 Thread Ethan Furman

On 06/30/2014 12:34 PM, Peter Otten wrote:

RainyDay wrote:


 def __eq__(self, other):
 return self._loc == getattr(other, "_loc", None)


Note that None is not a good default when _loc is expected to be a tuple:


In this case None is not being returned, but will be comparid with self._loc, 
so RainyDay is good there.

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a dict-like class that counts successful and failed key matches

2014-06-30 Thread Chris Angelico
On Tue, Jul 1, 2014 at 2:47 AM,   wrote:
> I'm not sure I understand. Are you saying that Chris's __getitem__ will
> not be called by other dict methods that would normally call this magic
> method and instead call the parent's __getitem__ directly (via super()
> or something similar?)?

He's pointing out the general principle behind what I said about the
.get() method; if you don't override .get() with your own
implementation, it won't pass the request through your __getitem__, so
it won't be statistically analyzed. That might be a good thing; it
means you're going to have to be explicit about what gets counted.

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


Re: Writing Multiple files at a times

2014-06-30 Thread Denis McMahon
On Mon, 30 Jun 2014 12:23:08 -0700, subhabangalore wrote:

> Thank you for your kind suggestion. But I am not being able to sort out,
> "fp = open( "scraped/body{:0>5d}.htm".format( n ), "w" ) "
> please suggest.

look up the python manual for string.format() and open() functions.

The line indicated opens a file for write whose name is generated by the 
string.format() function by inserting the number N formatted to 5 digits 
with leading zeroes into the string "scraped/bodyN.htm"

It expects you to have a subdir called "scraped" below the dir you're 
executing the code in.

Also, this newsgroup is *NOT* a substitute for reading the manual for 
basic python functions and methods.

Finally, if you don't understand basic string and file handling in 
python, why on earth are you trying to write code that arguably needs a 
level of competence in both? Perhaps as your starter project you should 
try something simpler, print "hello world" is traditional.

To understand the string formatting, try:

print "hello {:0>5d} world".format( 5 )
print "hello {:0>5d} world".format( 50 )
print "hello {:0>5d} world".format( 500 )
print "hello {:0>5d} world".format( 5000 )
print "hello {:0>5d} world".format( 5 )

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Validating Data Extracted from Files

2014-06-30 Thread Ari King
Hi,

I'm sourcing data from multiple excel files (workbooks) each with multiple 
worksheets. Prior to persisting the aggregated data, I want to validate it. I 
was thinking of creating classes to hold the data and validate type and content 
via methods. I'd appreciate feedback on this approach, suggestions on possibly 
better alternatives, and if there are existing libraries that provide this 
functionality. Thanks.

Best,
Ari 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python While loop Takes too much time.

2014-06-30 Thread Gregory Ewing

marco.naw...@colosso.nl wrote:

In the past I even dumped an EXCEL sheet as a
CSV file


That's probably the only way you'll speed things up
significantly. In my experience, accessing Excel via
COM is abysmally slow no matter how you go about it.

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


Re:Writing files at run time

2014-06-30 Thread Dave Angel
subhabangal...@gmail.com Wrote in message:
> Dear Group,
> 
> In my previous 
> post["https://groups.google.com/forum/#!topic/comp.lang.python/ZYjsskV5MgE";] 
> I was trying to discuss some issue on file writing. 
> 
> I got an associated issue. 
> 
> I am trying to crawl a link, through urllib and trying to store its results 
> in different files. As discussed I could work out a solution for this and 
> with your kind help trying to learn some new coding styles. 
> 
> Now, I am getting an associated issue. 
> 
> The crawler I am trying to construct would run daily-may be at a predefined 
> time. 
> [I am trying to set the parameter with "time" module]. 
> 
> Now, in the file(s) data are stored, are assigned or created at one time.
> 
> Data changes daily if I crawl daily newspapers. 
> 
> I generally change the name of the files with a sitting for few minutes 
> before a run. But this may not be the way. 
> 
> I am thinking of a smarter solution. 
> 
> If anyone of the esteemed members may kindly show a hint, how the name of the 
> storing files may be changed automatically as crawler runs every day, so that 
> data may be written there and retrieved. 
> 
> Thanking you in advance,
> Regards,
> Subhabrata Banerjee. 
>  
> 

Make a directory name from datetime. datetime. now () and put the
 files there. 

-- 
DaveA

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


Re: Translation of Python!

2014-06-30 Thread Steven D'Aprano
On Mon, 30 Jun 2014 14:24:46 -0600, Michael Torrie wrote:

> On 06/30/2014 12:37 PM, Doriven Basha wrote:
>> I want to translate it into my language like the chinese python
>> https://code.google.com/p/zhpy/w/list?q=label:Chinese can you help me?
> 
> I don't understand chinese, so I am not sure what this web page is
> about. Do you want to translate Python's messages (error tracebacks,
> etc) into Romanian?  

Doriven is Albanian, not Romanian.


> Or are you wanting to create a language that uses
> Python syntax but with Romanian keywords replacing english ones like if,
> else, while, def, etc?

Yes, that's what ChinesePython does:

http://reganmian.net/blog/2008/11/21/chinese-python-translating-a-programming-language/

http://www.chinesepython.org/english/english.html

For what it's worth, when this came up on the Python-Dev mailing list a 
few years ago, Guido gave his blessing to the idea.

I don't know how ChinesePython does it, but if I were doing this, I would 
use a pre-processor that translates custom source code into Python. Here 
are two joke languages that do something similar:

http://www.dalkescientific.com/writings/diary/archive/2007/06/01/lolpython.html

http://www.staringispolite.com/likepython/



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


Re: [OT] What can Nuitka do?

2014-06-30 Thread Michael Torrie
On 06/30/2014 07:36 AM, Chris Angelico wrote:
> Hmm. I'm not sure that it's necessarily that bad; I've done 3G-based
> X11 forwarding fairly successfully on occasion. Yes, it's potentially
> quite slow, but it certainly works - I've used SciTE, for instance,
> and I've used some GTK2 apps without problems. What do you mean by
> "modern toolkit"?

Modern toolkit is defined as anything that uses client-side rendering.
In the good old days of Motif and Xaw widgets, if a program wanted to
draw, the toolkit would instruct the server to draw primitives.
Rectangles, lines, etc.  Each widget would be created in its own window,
and events would be all handled on the server.  Unfortunately we quickly
hit some limits with that idea, as good and fast as it was.  First of
all, anti-aliased fonts were difficult to accomplish.  There were hacks
to do this early on, but it quickly became apparent that the actual
application could do a better job of it if it would just do the
rendering itself and have the X server draw it.  Not only anti-aliased
fonts, but also when you start talking about wanting to do layered
effects like alpha-blending.  All of this the app could do better and
more efficiently than the X server could, since the X server would have
had to round-trip to the app anyway to get the information since the X
server is in a different process (or different computer) and cannot
access the memory the app is using to store things.  Kieth Packard wrote
some X extensions to allow client-side rendering to be efficient and to
let the X server to handle RGBA images, and to composite them together.

Also, events in modern toolkits are done very differently than the
original X toolkits.  Instead of using multiple windows, clients now
just establish one window and then handle events and figure out what
widgets should receive the events client-side instead of server-side.
This allows handling of things like scrollable canvases.

Anyway, all of this improved the behavior and appearance of
applications.  When used locally, shared memory facilities make X pretty
fast, although latency is still quite high. There's no way to
synchronize frame redraws, so apps tear and stutter when you drag and
resize.  But over a network now, the nature of the X protocol means a
lot of round-trips to the server to do things. This is very apparent
when you run on a very slow connection. You might see widgets get drawn,
then erase, then drawn again.  Using a complex app like firefox, which
has another layer of abstraction over GTK that makes it even worse, is
very difficult on anything less than a LAN.  Or try a Java Swing app!
I've done it on occasion. I'd rather run Xvnc on the remote host and vnc
in than forward X.

FreeNX makes things very usable.
http://en.wikipedia.org/wiki/NX_technology describes how NX works.

I love that X11 apps work over a forward connection.  And I love that I
can run a remote window manager on a local X server if I wanted to.  But
I recognize X has it's problems and I can see how Wayland will
eventually be so much better while still letting me remote apps, which
is essential to me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] What can Nuitka do?

2014-06-30 Thread Michael Torrie
I highly recommend the talk by Daniel Stone who used to be a core X.org
developer.  He explains it quite well how X is used currently, and why
it has problems and why they are considered so hard to fix that Wayland
(and Mir) was created.

https://www.youtube.com/watch?v=RIctzAQOe44

One interesting point he made was the X server is no longer network
transparent like it used to be.  It is network capable now but when used
in that way (ssh forwarding), it's essentially done in the same way as
VNC, but more poorly because of the way X11 is architected.
-- 
https://mail.python.org/mailman/listinfo/python-list