Re: Editor Ergonomics [was: Important features for editors]

2013-07-08 Thread Giorgos Tzampanakis
On 2013-07-06, Skip Montanaro wrote:

> More likely, rms ignored the problem and had bad personal ergomonics:
> ignorance or lack of understanding of the problem, poor posture,
> wrists not in a neutral position, lack of breaks, etc.  If you stop to
> think about it, all text editors probably present similar issues for
> their users.  They all involve:
>
> * a lot of typing,

If you do touch-typing then this shouldn't cause any problems since the
finger/hand movement required is minimal.

> * use of modifier keys (ctrl, alt, command, etc)

Alt is not a problem, you hit them with your thumbs. Ctrl you should use
the bottom-outer part of your palm. If you actually hit ctrl with your
little finger then yes, this is a disaster waiting to happen.

> * movement between the mouse and the keyboard

Avoid at all costs. Use an editor that never needs the mouse (emacs or
vim).


-- 
Real (i.e. statistical) tennis and snooker player rankings and ratings:
http://www.statsfair.com/ 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Editor Ergonomics [was: Important features for editors]

2013-07-08 Thread Steven D'Aprano
On Sun, 07 Jul 2013 22:34:46 -0700, jussij wrote:

> On Sunday, July 7, 2013 12:41:02 PM UTC+10, Steven D'Aprano wrote:
> 
>> I am not an ergonomic expert, but I understand that moving from mouse
>> to keyboard actually helps prevent RSI, because it slows down the rate
>> of keystrokes and uses different muscle groups.
> 
> After 20+ years of coding using the Brief keyboard mapping I have so far
> I've gotten by with no perceivable RSI.
> 
> On the half dozen occasions that I can recall experienced wrist pain, I
> remember the pain being worst when trying to interfacing with the mouse.
> 
> So at least for me the mouse does not help.

Chances are that you had one of those ridiculously high mice that force 
your wrist to bend upwards ("dorsiflexion"), or otherwise were bending 
the wrist inappropriately. When mousing, your wrist should be as close to 
straight as possible. It helps if your mouse has a low profile, so that 
you can rest your wrist and forearm on the desk and control your mouse 
with your fingers without bending the wrist.

Assuming that you're keeping your wrists straight, then shifting from 
typing to mousing should reduce the chances of RSI because you are using 
different muscle groups. But if your mouse position is worse than your 
typing position, yes, that will probably cause problems...


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


Re: UnpicklingError: NEWOBJ class argument isn't a type object

2013-07-08 Thread Peter Otten
skunkwerk wrote:

> Hi,
>   I'm using a custom pickler that replaces any un-pickleable objects (such
>   as sockets or files) with a string representation of them, based on the
>   code from Shane Hathaway here:
> http://stackoverflow.com/questions/4080688/python-pickling-a-dict-with-
some-unpicklable-items
> 
> It works most of the time, but when I try to unpickle a Django
> HttpResponse, I get the following error: UnpicklingError: NEWOBJ class
> argument isn't a type object
> 
> I have no clue what the error actually means.  If it pickles okay, why
> should it not be able to unpickle?  Any ideas?

A simple way to provoke the error is to rebind the name referring to the 
class of the pickled object:

>>> import cPickle
>>> class A(object): pass
... 
>>> p = cPickle.dumps(A(), -1)
>>> cPickle.loads(p)
<__main__.A object at 0x7fce7bb58c50>
>>> A = 42
>>> cPickle.loads(p)
Traceback (most recent call last):
  File "", line 1, in 
cPickle.UnpicklingError: NEWOBJ class argument isn't a type object

You may be doing something to that effect.

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


Re: python adds an extra half space when reading from a string or list

2013-07-08 Thread Antoon Pardon
Op 06-07-13 00:40, ru...@yahoo.com schreef:
> On 07/04/2013 06:09 AM, Antoon Pardon wrote:
>> Op 03-07-13 19:11, ru...@yahoo.com schreef:
>>> On 07/03/2013 03:21 AM, Antoon Pardon wrote:
 Op 03-07-13 02:30, ru...@yahoo.com schreef:
> If your going to point out something negative about someone
> then do so politely.  Ask yourself if you were pointing out 
> incompetence to your boss (or anyone else where impoliteness
> could have real consequences for you) if you would say, 
> "you're incompetent." 
 And so we shift from no problem speaking bluntly or clearly
 to wording it in a way that wouldn't antagonize your boss
 too much.
>>> As I pointed out, emotionally-loaded, judgmental language 
>>> *is not* clear.
>> Well that is true, but mostly in the trivial sense that
>> language is rarely clear even when you are talking facts.
> Its true in more than a trivial sense.
>
>> When I meet someone new and I talk about my love of spaghetti
>> and the other inivites me to the spaghetti evening the next
>> day, that can turn out to be a big disappointment because
>> when I talk about spaghetti, I mean a carbonarra while I
>> was invited to a bolognaise-evening.
> Of course there is some degree of uncertainty.  But that
> uncertainty is relatively small when compared with the
> range of possible food you might have been served had 
> your evening's companion not specified "spaghetti".
>
> Had he or she invited you to a really "delicious" meal
> on the other hand, the uncertainty about the what 
> "delicious" means would far greater.  Unless you know 
> the person, "delicious" is so subjective as to have very
> little meaning since its meaning varies between people
> much more than "spaghetti" does.
That is not true. Subjective and unclear are not the
same. And that you don't know what kind of food someone
find delicious, doesn't make it unclear what kind of
expectations you (try to) evoke when you promisse him
a delicious meal.

When you go to someone's restaurant buddies and tell them
you want to cook him a delicious meal, do they have suggestions?
Then those buddies will find that question clear enough to
come up with useful answers. And I doubt that you can get
just as useful answers by asking about objective facts.


> Describing someone as "stupid", "incompetent", "a 
> dick", etc has a similar high degree of subjectivity
> and its meaning depends more on the sayer than on any 
> objective attribute of the subject.
I doubt that. Subjective is not the same as arbitrary.
We as humans react in large degree the same to the same
kind of stimuli. If someone tells me something tastes
sweet, then that tells me more about what he is tasting
than about him. Especially if more than one person reports
the same.


> If you can tell me something objective about the subject,
> then that may be helpful to me in deciding how to respond 
> to him or her.  If you just spout subjective invective, 
> then its just noise because I don't know enough about 
> you to trust your judgment.

And why should you trust my objective statement? The fact
that the statement is objective, doesn't mean I am qualified
in making it.


>   (Advanced technical python 
> knowledge does not qualify one in judging other human 
> beings.)  And since I'm reading the thread I have access 
> to the same info you do, and can form my own subjective
> opinion.  Judging other people is in my opinion a moral 
> action that is too important to delegate or to do by just
> going along with the crowd.

So nobody is stopping you AFAICS.

> So such subjective, emotionally-loaded, judgmental responses 
> provide little benefit to others, amplify whatever negative
> tone was created by the troll and stimulate the troll.  The
> only benefits are to you who gets to vent and argue, and a 
> (hopefully few) voyeurs and fellow vigilantes who enjoy 
> watching and joining in on that kind of flamage.

This is just your subjective emotional evaluation. By your
own words why should I trust you? Why should we see the benefits
to the vigilantes and the voyeurs as little? Why should we
see the tone that is created by the troll as negative? Why
should we hope that the voyeurs and vigilantes are few?

Doesn't this all just say more about you than about the trolls,
vigilantes and voyeurs? Why should I take your judgement over that
of those you call trolls, vigilantes and voyeurs? Why do you
use the words "troll", "vigilante" and "voyeur", which are
emotionnaly laden, instead of stating objective facts?


>> Are you saying we should either help the person with his
>> (python) problem or decline any help no matter how nefarious
>> the goals he wants to accomplish or are you saying these
>> examples are not serious enough so people should show some
>> tolerance in these cases?
> The former.

Then I strongly disagree. If at some point a pedophile would
come to this group to ask for advice for his python program
he's using to spy on the kids in the neighbo

Re: Tutorials on Jinja

2013-07-08 Thread dtbulmer2
On Wednesday, June 24, 2009 11:46:55 AM UTC-7, Saurabh wrote:
> Hi All,
> 
> I am trying to move my application on a MVC architecture and plan to
> use Jinja for the same. Can anyone provide me with few quick links
> that might help me to get started with Jinja?
> 
> Thanks,
> Saby

this is a site that uses jinja2

https://github.com/davidnuon/davidnuon.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie. Need help

2013-07-08 Thread Sanza101
I just started using Python recently, and i need help with the following: 
Please assist.

1.  Create another function that generates a random number (You will have 
to import the relevant library to do this)
2.  Create a function that is called from the main function, that accepts a 
number as a parameter and determines if the number is even or odd
3.  Now enhance your script to generate 10 random even numbers and write 
them to a file

So far what i have done is:
import random
def main():
pass

if __name__ == '__main__':
main()
for evenNumber in range (0, 20, 2):
print random.randrange(0, 101, 2)

f = open("C:\Users\Documents\Myproj.txt", "w");
print f
f = open("C:\Users\Documents\Myproj.txt", "a");
print f

value = random.randrange(0, 101, 2, )
value1 = random.randrange(0, 201, 2, )
value2 = random.randrange(0, 301, 2, )

myString = str(value)
myString1 = str(value1)
myString2 = str(value2)

print f.write(myString)
print f.write(myString1)
print f.write(myString2)
f.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Illegal suggestions on python list

2013-07-08 Thread Joshua Landau
On 5 July 2013 08:34, Chris Angelico  wrote:
> On Fri, Jul 5, 2013 at 5:23 PM, Νίκος Gr33k  wrote:
>> Of course we all know that a serial/patch/keygen/crack can be found for this
>> great edit very easily on warez or torrentz sites so it was like a common
>> secret to all of us.
>
> Actually no, I don't know that that's available.

Seriously? I thought you had internet access...

/onlyhalfjoking

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


Re: Geo Location extracted from visitors ip address

2013-07-08 Thread Joel Goldstick
On Fri, Jul 5, 2013 at 3:08 PM, Νίκος Gr33k  wrote:

> Is there a way to extract out of some environmental variable the Geo
> location of the user being the city the user visits out website from?
>
> Perhaps by utilizing his originated ip address?
>
> --
> What is now proved was at first only imagined!
> --
> http://mail.python.org/**mailman/listinfo/python-list
>

Google shows lots of results.  This one might work for you:
http://freegeoip.net/

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Geo Location extracted from visitors ip address

2013-07-08 Thread Jerry Hill
On Fri, Jul 5, 2013 at 3:08 PM, Νίκος Gr33k  wrote:
> Is there a way to extract out of some environmental variable the Geo
> location of the user being the city the user visits out website from?
>
> Perhaps by utilizing his originated ip address?

No, you'd need to take the originating IP address and look it up in a
geolocation database or submit it to a geolocation service and get the
response back from them.  It's not stored in any environment
variables.

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


Re: Geo Location extracted from visitors ip address

2013-07-08 Thread Robert Kern

On 2013-07-06 09:41, Νίκος Gr33k wrote:

Στις 6/7/2013 11:30 πμ, ο/η Chris Angelico έγραψε:

On Sat, Jul 6, 2013 at 6:01 PM, � Gr33k  wrote:

Is there any way to pinpoint the visitor's exact location?


Yes. You ask them to fill in a shipping address. They may still lie,
or they may choose to not answer, but that's the best you're going to
achieve without getting a wizard to cast Scrying.


No, no registration requirements.

you know when i go to maps.google.com its always find my exact city of location
and not just say Europe/Athens.

and twitter and facebook too both of them pinpoint my _exact_ location.

How are they able to do it? We need the same way.


They use client-side JavaScript. This is a relatively new API available in most, 
but not all, recent browsers. This information will not be available to your CGI 
script. You will have to generate HTML with the proper JavaScript to get the 
geolocation (if the user allows it) and then send it back to your server through 
a different CGI script (or web application endpoint).


  http://diveintohtml5.info/geolocation.html

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


AMQP listening and user-facing daemon

2013-07-08 Thread Justin Chiu

Hi all,

What is the best approach to writing a concurrent daemon that can 
execute callbacks for different types of events (AMQP messages, parsed 
output of a subprocess, HTTP requests)?


I am considering [twisted][1], the built-in [threading][2] module, and 
[greenlet][3]. I must admit that I am very unfamiliar with concurrent 
programming and Python programming in general (formerly a data analysis 
driven procedural programmer). Any resources on threaded/concurrent 
programming (specifically daemons...not just multi-threading a single 
task) would be much appreciated.


Thank you.

Details:

1) Listens into AMQP messaging queues and executes callbacks when 
messages arrive.
Example: Immediately after startup, the daemon continuously listens to 
the [Openstack Notifications messaging queue][4]. When a virtual machine 
is launched, a notification is generated by Openstack with the hostname, 
IP address, etc. The daemon should read this message and write some info 
to a log (or POST the info to a server, or notify the user...something 
simple).


2) Parse the output of a subprocess and execute callbacks based on the 
output.
Example: Every 30 seconds, a system command "[qstat][5]" is run to query 
a job resource manager (e.g. TORQUE). Similar callbacks to 1).


3) Receive requests from a user and process them. I think this will be 
via WSGI HTTP.
Example: User submits an XML template with virtual machine templates. 
The daemon does some simple XML parsing and writes a job script for the 
job resource manager. The job is submitted to the resource manager and 
the daemon continually checks for the status of the job with "qstat" and 
for messages from AMQP. It should return "live" feedback to the user and 
write to a log.


  [1]: https://twistedmatrix.com/trac/wiki/Documentation
  [2]: http://docs.python.org/2/library/threading.html
  [3]: http://greenlet.readthedocs.org/en/latest/
  [4]: 
https://wiki.openstack.org/wiki/NotificationEventExamples#Immediate_Notifications:

  [5]: http://www.clusterresources.com/torquedocs21/commands/qstat.shtml

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


Re: Geo Location extracted from visitors ip address

2013-07-08 Thread Support by Νίκος

Στις 5/7/2013 10:28 μμ, ο/η Jerry Hill έγραψε:

On Fri, Jul 5, 2013 at 3:08 PM, Νίκος Gr33k  wrote:

Is there a way to extract out of some environmental variable the Geo
location of the user being the city the user visits out website from?

Perhaps by utilizing his originated ip address?

No, you'd need to take the originating IP address and look it up in a
geolocation database or submit it to a geolocation service and get the
response back from them.  It's not stored in any environment
variables.

I see but i dont know how to do this Geo location lookups.
Can you give me more specific details please?
--
Webhost 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Geo Location extracted from visitors ip address

2013-07-08 Thread Chris Angelico
On Sat, Jul 6, 2013 at 7:18 AM, Dave Angel  wrote:
> On 07/05/2013 04:44 PM, Tim Roberts wrote:
>>
>> ? Gr33k  wrote:
>>>
>>>
>>> Is there a way to extract out of some environmental variable the Geo
>>> location of the user being the city the user visits out website from?
>>>
>>> Perhaps by utilizing his originated ip address?
>>
>>
>> It is possible to look up the geographic region associated with a block of
>> IP addresses.  That does not necessarily bear any resemblence to the
>> actual
>> location of the user.  It tells you the location of the Internet provider
>> that registered the IP addresses.
>>
>
> To be more specific, the last time I checked, my IP address is registered to
> a location over 1000 miles away.  And it's not a dedicated IP address, so it
> could very well be used tomorrow by someone 200 nmiles the other side of the
> registered location.
>
> Further, I sometimes use other ISP's with different addresses, even when I
> don't leave the house.  And once I leave, anything's possible.

That said, though, geolocation is usually accurate enough to report
which country you're in. For basic statistical analysis, that's
generally sufficient.

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


capture html screen with pexpect

2013-07-08 Thread inq1ltd
python help,

I can log into a web site with pexpect but
what I want to do is pipe the opening window 
to a file. 

Logging into the site opens the site window
 but I can't get the window to a file. 

I can't use screen capture I need to get
pexpect to pipe it to a txt file.

Any help will be appreciated.
jimonliinux

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


A small question about PEP 8

2013-07-08 Thread Xue Fuqiao
Hi all,

(English is not my native language; please excuse typing errors.)

I'm a Python newbie and just started reading PEP 8.  PEP says:

---
|The closing brace/bracket/parenthesis on multi-line constructs may
|either line up under the last item of the list, as in:
|
|my_list = [
|1, 2, 3,
|4, 5, 6,
|]
|result = some_function_that_takes_arguments(
|'a', 'b', 'c',
|'d', 'e', 'f',
|)
---

I think the last item in my_list/result is 6/'f', respectively.  So why
doesn't the bracket/paren line up _under_ the last item?  ISTM the code
isn't consistent with the description.

I have searched the archive of c.l.p and the web, but nothing helped.
Can anyone point me in the right direction?

--
Best regards, Xue Fuqiao.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Important features for editors

2013-07-08 Thread Skip Montanaro
>> I couldn't live without the keyboard macro record and playback.
>
> I used to work with a programmer who couldn't live without his insulin
> injections.

Hyperbole aside, two of my most common "crutches" are Emacs macros and
bash history.  Given how useful macros are, I find it very odd that
recent versions of GNU Emacs dispensed with the old key binding to C-x
c.

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


Re: Newbie. Need help

2013-07-08 Thread Joshua Landau
On 8 July 2013 09:53, Sanza101  wrote:
> I just started using Python recently, and i need help with the following: 
> Please assist.

Rather than saying you want help with "Please assist", why don't you
ask a question?

I find when people start their post with "I need help, please help"
they forget that (a) what else would we try to do and (b) to state
what they need help with.

> 1.  Create another function that generates a random number (You will have 
> to import the relevant library to do this)
> 2.  Create a function that is called from the main function, that accepts 
> a number as a parameter and determines if the number is even or odd
> 3.  Now enhance your script to generate 10 random even numbers and write 
> them to a file

It's normally nice to state when something's a homework. It puts you
on much better, more honest terms than if you don't. We won't blank
you if you tell us or anything.

> So far what i have done is:
> import random
> def main():
> pass
>
> if __name__ == '__main__':
> main()
> for evenNumber in range (0, 20, 2):
> print random.randrange(0, 101, 2)
>
> f = open("C:\Users\Documents\Myproj.txt", "w");
> print f
> f = open("C:\Users\Documents\Myproj.txt", "a");
> print f
>
> value = random.randrange(0, 101, 2, )
> value1 = random.randrange(0, 201, 2, )
> value2 = random.randrange(0, 301, 2, )
>
> myString = str(value)
> myString1 = str(value1)
> myString2 = str(value2)
>
> print f.write(myString)
> print f.write(myString1)
> print f.write(myString2)
> f.close()

OK... so? What do you need help with?

I'll guide you through what you've done, and why it doesn't do what you want.

> import random

So far so good.

> def main():
> pass

This does.. nothing.
You probably want to put everything inside your main function, so it
is called only if "__name__ == '__main__'". This is done so that is
people "import yourmodule" then they won't immediately have lots of
things happening that aren't useful -- like putting numbers in files,
but they can still use your functions that you write.

> if __name__ == '__main__':
> main()

That's fine.

> for evenNumber in range (0, 20, 2):
> print random.randrange(0, 101, 2)

You do "for evenNumber in ..." but never use "evenNumber". you should
write "for i in range(10):" which is a much better way of saying "do
this 10 times".

Additionally, no-one in python seems to use thisWayOfNamingThings.
Whilst it's not _wrong_, per se, it's not standard either. You'll be
happier in the long run if you learn to use this_way_of_naming_things.

You were asked to "Create another function that generates a random
number". I'm not really sure what this means, but it sounds to me like
you want to do:

def generate_random_number():
...

which I would just write: "generate_random_number = random.randrange".
Yes, just use what you already have.

> f = open("C:\Users\Documents\Myproj.txt", "w");

Oh no! What is this ";" on the end? DESTROY IT NOW.

> print f

This just prints "". Why did you do this?

Also, the recommended way to open a file and use it is like this:

with open("C:\Users\Documents\Myproj.txt", "w") as f:
print f

This makes sure you don't forget to close it, and it handles some
stuff really cleverly and well. You don't need to know what it all
means yet, but just know that for "open" it does The Right Thing™.

> f = open("C:\Users\Documents\Myproj.txt", "a");
> print f

Exactly the same comments.

> value = random.randrange(0, 101, 2, )
> value1 = random.randrange(0, 201, 2, )
> value2 = random.randrange(0, 301, 2, )

Oh.. kay. Why do you have a trailing ", "? Just do:

> value = random.randrange(0, 101, 2)
> value1 = random.randrange(0, 201, 2)
> value2 = random.randrange(0, 301, 2)

Also, why are they "value", "value1" and "value2"? Those names make no
sense. You could always put them in a tuple (like a list of things):

random_numbers = (
random.randrange(0, 101, 2),
random.randrange(0, 201, 2),
random.randrange(0, 301, 2)
)

and then you can index them like "random_numbers[0]" instead of
"value", "random_numbers[1]" instead of "value1" and
"random_numbers[2]" instead of "value2". I don't know.

> myString = str(value)
> myString1 = str(value1)
> myString2 = str(value2)

Urm... "myString"? What does that even mean? If it were me, I'd
convert when I need to:

> print f.write(str(value))
> print f.write(str(value1))
> print f.write(str(value2))

Also, what do you think the "print" does here? It doesn't print the
value. You have no reason for the print, and should remove it.

> f.close()

If you use "with open(...) as f:" you do not need to close f, btw.


So back to the tasks:


> 1.  Create another function that generates a random number (You will have 
> to import the relevant library to do this)

As before, this is a stupid question. If you know what it means, do explain.


> 2.  Create a function that is called from the main function, that accepts 
> a number as a parameter and det

Re: A small question about PEP 8

2013-07-08 Thread Joshua Landau
On 8 July 2013 00:32, Xue Fuqiao  wrote:
> Hi all,
>
> (English is not my native language; please excuse typing errors.)
>
> I'm a Python newbie and just started reading PEP 8.  PEP says:
>
> ---
> |The closing brace/bracket/parenthesis on multi-line constructs may
> |either line up under the last item of the list, as in:
> |
> |my_list = [
> |1, 2, 3,
> |4, 5, 6,
> |]
> |result = some_function_that_takes_arguments(
> |'a', 'b', 'c',
> |'d', 'e', 'f',
> |)
> ---
>
> I think the last item in my_list/result is 6/'f', respectively.  So why
> doesn't the bracket/paren line up _under_ the last item?  ISTM the code
> isn't consistent with the description.
>
> I have searched the archive of c.l.p and the web, but nothing helped.
> Can anyone point me in the right direction?

You will grow to be a wonderful pedant. What it means is that the
indentation will match the last one. Imagine:

"""
a_wonderful_set_of_things = {
bannanas_made_of_apples,
chocolate_covered_horns,
doors_that_slide,
china_but_on_the_moon,
buffalo_with_windy_hair,
not_missing_an_end_brace
"""¹

Now, there are several places you can put the end brace. You can (be a
massive fool and) put it after the last item:

"""
a_wonderful_set_of_things = {
...,
not_missing_an_end_brace}
"""

You can also (be a fool and) put it at the same *indentation*:

"""
a_wonderful_set_of_things = {
...,
not_missing_an_end_brace
}
"""

Or you can (be sane) and put it at no indentation:

"""
a_wonderful_set_of_things = {
...,
not_missing_an_end_brace
}
"""

Theoretically, there are more places you could put it (but we won't go
there... *shudder*).

The second of these is the one that PEP 8 was trying to explain. I
agree wording could be improved, but hey. You can file a bug report at
bugs.python.org if you care enough.

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


Re: capture html screen with pexpect

2013-07-08 Thread Dave Angel

On 07/07/2013 01:06 PM, inq1ltd wrote:

python help,

I can log into a web site with pexpect but
what I want to do is pipe the opening window
to a file.

Logging into the site opens the site window
  but I can't get the window to a file.

I can't use screen capture I need to get
pexpect to pipe it to a txt file.



What have you tried?  What environment are you in?  What's the exact 
assignment?


I'd use wget, since I'm on Linux, and it's simple.


davea@think2:~$ wget google.com

creates a file called index.html in my cwd


--
DaveA

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


Re: A small question about PEP 8

2013-07-08 Thread Steven D'Aprano
On Mon, 08 Jul 2013 07:32:01 +0800, Xue Fuqiao wrote:

> Hi all,
> 
> (English is not my native language; please excuse typing errors.)
> 
> I'm a Python newbie and just started reading PEP 8.  PEP says:
> 
> ---
> |The closing brace/bracket/parenthesis on multi-line constructs may
> |either line up under the last item of the list, as in: 
> |
> |my_list = [
> |1, 2, 3,
> |4, 5, 6,
> |]
> |result = some_function_that_takes_arguments(
> |'a', 'b', 'c',
> |'d', 'e', 'f',
> |)
> ---
> 
> I think the last item in my_list/result is 6/'f', respectively.  So why
> doesn't the bracket/paren line up _under_ the last item?  ISTM the code
> isn't consistent with the description.

I agree. I think it is just a mistake, and should say "under the FIRST 
item of the list".



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


Re: Newbie. Need help

2013-07-08 Thread Alister
On Mon, 08 Jul 2013 01:53:06 -0700, Sanza101 wrote:

> I just started using Python recently, and i need help with the
> following: Please assist.
> 
> 1.Create another function that generates a random number (You will 
have
> to import the relevant library to do this)
> 2.Create a function that is called from the main function, that 
accepts
> a number as a parameter and determines if the number is even or odd 3.
> Now enhance your script to generate 10 random even numbers and write
> them to a file
> 
> So far what i have done is:
> import random def main():
> pass
> 
> if __name__ == '__main__':
> main()
> for evenNumber in range (0, 20, 2):
> print random.randrange(0, 101, 2)
> 
> f = open("C:\Users\Documents\Myproj.txt", "w");
> print f f = open("C:\Users\Documents\Myproj.txt", "a");
> print f
> 
> value = random.randrange(0, 101, 2, )
> value1 = random.randrange(0, 201, 2, )
> value2 = random.randrange(0, 301, 2, )
> 
> myString = str(value)
> myString1 = str(value1)
> myString2 = str(value2)
> 
> print f.write(myString)
> print f.write(myString1)
> print f.write(myString2)
> f.close()
As this is course work I wont give you answers just pointers to help.

from the wording of the question your teacher is probably more interested 
in you understanding how to define functions.

so from the design requirements you will need something like

def get_random():
#your code foes here

def is_even(number):
#you code here

you then need to loop through the code writing to file each time you get 
an even result.

a for loop is probably not the best type of loop for this task.

once you have some more code I am sure we will help further if you get 
stuck with any specifics.



-- 
The computer is to the information industry roughly what the
central power station is to the electrical industry.
-- Peter Drucker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default scope of variables

2013-07-08 Thread Neil Cerutti
On 2013-07-07, Steven D'Aprano  wrote:
> On Fri, 05 Jul 2013 13:24:43 +, Neil Cerutti wrote:
>
>> for x in range(4):
>>print(x)
>> print(x) # Vader NOoOO!!!
>
> That loops do *not* introduce a new scope is a feature, not a bug. It is 
> *really* useful to be able to use the value of x after the loop has 
> finished.

I don't buy necessarily buy that it's "*really*" useful but I do
like introducing new names in (not really the scope of)
if/elif/else and for statement blocks.

z = record["Zip"]
if int(z) > 9:
zip_code = z[:-4].rjust(5, "0")
zip4 = z[-4:]
else:
  zip_code = z.rjust(5, "0")
  zip4 = ""


As opposed to:

zip_code = None
zip4 = None
z = record["Zip"]
if int(z) > 9:
zip_code = z[:-4].rjust(5, "0")
zip4 = z[-4:]
else:
zip_code = z.rjust(5, "0")
zip4 = ""

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


How do I write a script to generate 10 random EVEN numbers and write them to a .txt file?

2013-07-08 Thread Kenz09
Hi, I have been given a task to do. I am a new to programming and Python.
My task is to :
-Create a function that is called from the main function, that accepts a number 
as a parameter and determines if the number is even or odd.
the next one is,

-To create another function that generates a random number, and basically when 
i print this function, it should give me a list of random number separated by a 
"," commma or in a list.

-And lastly to enhance my script to generate 10 random EVEN numbers and write 
them to a .txt file.

This what I have done so far.

import random

if __name__ == '__main__':
main()
for i in range(10):
print random.randrange(0, 101, 2)

with open ("C:\Users\Kenz09\Documents\Myproj.txt", "w") as f:
print f
f = open("C:\Users\Kenz09\Documents\Myproj.txt", "a");
print f

value = (
random.randrange (0, 101, 2),
random.randrange(0, 201, 2),
random.randrange(0, 301, 2)
)

random_numbers[0]
random_numbers[1]
random_numbers[2]

print f.write(str(value))
print f.write(str(value1))
print f.write(str(value2))
f.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A small question about PEP 8

2013-07-08 Thread Steven D'Aprano
On Mon, 08 Jul 2013 11:39:21 +0100, Joshua Landau wrote:

> On 8 July 2013 00:32, Xue Fuqiao  wrote:
>> Hi all,
>>
>> (English is not my native language; please excuse typing errors.)
>>
>> I'm a Python newbie and just started reading PEP 8.  PEP says:
>>
>> ---
>> |The closing brace/bracket/parenthesis on multi-line constructs may
>> |either line up under the last item of the list, as in: |
>> |my_list = [
>> |1, 2, 3,
>> |4, 5, 6,
>> |]
>> |result = some_function_that_takes_arguments(
>> |'a', 'b', 'c',
>> |'d', 'e', 'f',
>> |)
>> ---
>>
>> I think the last item in my_list/result is 6/'f', respectively.  So why
>> doesn't the bracket/paren line up _under_ the last item?  ISTM the code
>> isn't consistent with the description.
>>
>> I have searched the archive of c.l.p and the web, but nothing helped.
>> Can anyone point me in the right direction?
> 
> You will grow to be a wonderful pedant. What it means is that the
> indentation will match the last one.

That's obvious from the example given, but that's nothing like the 
description given.




 Imagine:
> 
> """
> a_wonderful_set_of_things = {
> bannanas_made_of_apples,
> chocolate_covered_horns,
> doors_that_slide,
> china_but_on_the_moon,
> buffalo_with_windy_hair,
> not_missing_an_end_brace
> """¹
> 
> Now, there are several places you can put the end brace. You can (be a
> massive fool and) put it after the last item:
> 
> """
> a_wonderful_set_of_things = {
> ...,
> not_missing_an_end_brace}
> """

Well, call me a fool then, because when I have code that extends over 
*one* additional line, I prefer that:

raise ValueError(
"Some error message too long to fit on the above line")

rather than:

raise ValueError(
"Some error message too long to fit on the above line"
)


> You can also (be a fool and) put it at the same *indentation*:
> 
> """
> a_wonderful_set_of_things = {
> ...,
> not_missing_an_end_brace
> }
> """

Call me a fool again, since I prefer this when there are more than one 
additional line. At least this time I'm in good company, since that's 
recommended by PEP 8.


> Or you can (be sane) and put it at no indentation:
> 
> """
> a_wonderful_set_of_things = {
> ...,
> not_missing_an_end_brace
> }
> """

I consider that the least aesthetically pleasing, and also rather awkward:


some_result = some_function(
arg1, arg2, arg3, arg4, 
[item1, item2, item3, item4,
  item5, item6, item7, 
  item8, item9, item10,
], 
   arg6, key=spam, word=eggs, 
   extras=None, foo=bar,
)


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


Re: How do I write a script to generate 10 random EVEN numbers and write them to a .txt file?

2013-07-08 Thread Dave Angel

On 07/08/2013 08:01 AM, Kenz09 wrote:

Hi, I have been given a task to do. I am a new to programming and Python.
My task is to :
-Create a function that is called from the main function, that accepts a number 
as a parameter and determines if the number is even or odd.
the next one is,

-To create another function that generates a random number, and basically when i print 
this function, it should give me a list of random number separated by a "," 
commma or in a list.

-And lastly to enhance my script to generate 10 random EVEN numbers and write 
them to a .txt file.



One of your classmates has already posted the question.  However, you 
win the prize for a better subject line.  Or are you the same student, 
changing your name and wasting our time by starting a new thread.



This what I have done so far.


Where's your main function?



import random

if __name__ == '__main__':
 main()
 for i in range(10):
 print random.randrange(0, 101, 2)


Why is everything at top level, and not inside the function(s) ?



with open ("C:\Users\Kenz09\Documents\Myproj.txt", "w") as f:
 print f
f = open("C:\Users\Kenz09\Documents\Myproj.txt", "a");


That semicolon comes from another language.  Very seldom any need for it 
in Python.



print f

value = (
random.randrange (0, 101, 2),
random.randrange(0, 201, 2),
random.randrange(0, 301, 2)
)


The reason the instructor told you to do 10 is probably to discourage 
you from typing separate statements for all 10.  You're undoubtedly 
supposed to use a loop.




random_numbers[0]
random_numbers[1]
random_numbers[2]


When you asigned it, you called it value, but now you expect it to have 
another name?




print f.write(str(value))
print f.write(str(value1))
print f.write(str(value2))
f.close()



Why not start by doing the first statement of the assignment, and if you 
can't make it work, or don't understand some part of the question, ask 
again?  Show your work, not just a bunch of random statements, most of 
which won't execute.


If I were wording that first question, I'd say something like:

"""
Create a function that accepts a integer as a parameter and determines 
if the number is even or odd, returning a boolean value accordingly.


Call that function multiple times from the main function, with a variety 
of values, indicating for each whether it's even or odd.

"""


--
DaveA

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


Re: A small question about PEP 8

2013-07-08 Thread Dave Angel

On 07/08/2013 08:02 AM, Steven D'Aprano wrote:

On Mon, 08 Jul 2013 11:39:21 +0100, Joshua Landau wrote:






Or you can (be sane) and put it at no indentation:

"""
a_wonderful_set_of_things = {
 ...,
 not_missing_an_end_brace
}
"""


I consider that the least aesthetically pleasing, and also rather awkward:


some_result = some_function(
 arg1, arg2, arg3, arg4,
 [item1, item2, item3, item4,
   item5, item6, item7,
   item8, item9, item10,
],
arg6, key=spam, word=eggs,
extras=None, foo=bar,
)


or even better:

class  MyClass:
def my_method(self):
if self.flag:
self.value.append(
 arg1,
 arg2,
 arg3
)
return self.value




--
DaveA

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


ssl handshake operation timed out on Python 3.3.2

2013-07-08 Thread Benedict Verheyen
Hi,


for a project, I need to post data to some aspx pages.
The aspx pages are hosted by another company.
I develop on a virtual Debian Wheezy (Virtual box) running on Windows.
I couldn't get the code to run either on Windows nor Linux.

On my testserver (also a Debian Linux Wheezy) however, the code works with 
Python 2.7.3 but not with Python 3.3.2. Another difference is that the 
testserver has a direct ip, so nothing in between the machine and the 
internet. I checked the firewall, the traffic passes without a problem.

The error I get is that the SSL handshake operation timed out.
I tried some code that specifies the ssl protocol but the results are the 
same.

I'm stumped. Does anyone have an idea as to why this code works on python 
2.7 and not on python 3.3?
To summarize, on my dev machine, it doesn't work with either Python 2.7.3 
or 3.3.2, on my test machine, it works with Python 2.7.3 but not with 
Python 3.3.2

An excerpt of the code:
...
data = {'_UserName_': username, '_Password_': password}
headers = {'Cache-control': 'private','Connection':'Keep-Alive'}
r = requests.post("https://url.aspx";, data=data, headers=headers, 
timeout=8)


Any ideas would be welcome,

Cheers,
Benedict

-- 
Benedict Verheyen   Debian, Python and Django user
GnuPG Public Key 0x712CBB8D

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


Re: Newbie. Need help

2013-07-08 Thread Joshua Landau
On 8 July 2013 13:05, Sandile Mnukwa  wrote:
> Hi Joshua,

Hello.

You replied off-list (to me only, not to Python-list). I imagine this
was a mistake, so I'm posting to Python-list again. If this wasn't a
mistake, then I apologize and suggest telling people when you mean to
reply off-list.

Also, you top-posted, which isn't the right thing to do. This means
you wrote your reply above the copy of the text you were replying to
-- you should write below. You should also delete all of the parts
that you aren't responding to, so people know what you are talking
about.

> Thanks for the help so far.
> Just been panicking about learning the language...
>
> I have been given a task to do. I am a new to programming and Python.
> My task is to :
> -Create a function that is called from the main function, that accepts a 
> number as a parameter and determines if the number is even or odd.
> the next one is,

You have done:

def main():
pass

So you know how to define a *main function*. This should take a parameter.

Do you know how to make a function accept a parameter?

Once you have that parameter, you need to check whether it is even or
odd. If you don't know how to do this, check the link I gave in my
last post or try a Google search for "python check number even odd".

Knowing how to look for answers to simple (and later complicated)
problems is important to being a good programmer.

> -To create another function that generates a random number, and basically 
> when i print this function, it should give me a list of random number 
> separated by a "," commma or in a list.

OK, that's good. You know how to generate random numbers
(random.randrange), so now you want to define a function.

def generate_numbers():
...

You want to *return* a *list* of *random numbers*:

list_of_random_numbers = []

for i in range(10):
random_number =  #  You fill this in

list_of_random_numbers.append(random_number)

then you want to *return* the *list_of_random_numbers*. Do you know
how to return values?

> -And lastly to enhance my script to generate 10 random EVEN numbers and write 
> them to a .txt file. (This task is the most important of them all)

You know how to generate 10 random even numbers. I know you know this
because you have done:
> for i in range(10):
> print random.randrange(0, 101, 2)

You should assign each random number to a name (using "=").
*Inside* your loop, you want to do SOME_FILE.write(str(RANDOM_NUMBER))

> What I have done so far.
>
> import random
>
> if __name__ == '__main__':
> main()
> for i in range(10):
> print random.randrange(0, 101, 2)

When I said to put this in the main function, I meant the *function*,
not here. This works, but it isn't what people normally do. See how
you call "main()" inside here? Thus, when you have the

> for i in range(10):
> print random.randrange(0, 101, 2)

inside "main()" it will get run anyway. Does this make sense?

> with open ("C:\Users\Kenz09\Documents\Myproj.txt", "w") as f:
> print f

When I said use "with", I mean use "with" *everywhere*, not just here.
So you should use this same pattern in the other places you open
files.

You will need to indent the *whole* of the code that requires use of
the file "f" when you do this.

> f = open("C:\Users\Kenz09\Documents\Myproj.txt", "a");
> print f
>
> value = (
> random.randrange (0, 101, 2),
> random.randrange(0, 201, 2),
> random.randrange(0, 301, 2)
> )
>
> random_numbers[0]
> random_numbers[1]
> random_numbers[2]
>
> print f.write(str(value))
> print f.write(str(value1))
> print f.write(str(value2))
> f.close()

Remember that I'm telling you this so that you know what to do, not so
you can take the code I give you. I will not give you complete
solutions -- if you ask what "5 + 5" is I will show you how to work
out "4 + 4", and then you can apply that to the original problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A small question about PEP 8

2013-07-08 Thread Joshua Landau
On 8 July 2013 13:02, Steven D'Aprano
 wrote:
> On Mon, 08 Jul 2013 11:39:21 +0100, Joshua Landau wrote:
>  Imagine:
>>
>> """
>> a_wonderful_set_of_things = {
>> bannanas_made_of_apples,
>> chocolate_covered_horns,
>> doors_that_slide,
>> china_but_on_the_moon,
>> buffalo_with_windy_hair,
>> not_missing_an_end_brace
>> """¹
>>
>> Now, there are several places you can put the end brace. You can (be a
>> massive fool and) put it after the last item:
>>
>> """
>> a_wonderful_set_of_things = {
>> ...,
>> not_missing_an_end_brace}
>> """
>
> Well, call me a fool then, because when I have code that extends over
> *one* additional line, I prefer that:
>
> raise ValueError(
> "Some error message too long to fit on the above line")
>
> rather than:
>
> raise ValueError(
> "Some error message too long to fit on the above line"
> )

Fool.

>> You can also (be a fool and) put it at the same *indentation*:
>>
>> """
>> a_wonderful_set_of_things = {
>> ...,
>> not_missing_an_end_brace
>> }
>> """
>
> Call me a fool again, since I prefer this when there are more than one
> additional line. At least this time I'm in good company, since that's
> recommended by PEP 8.

Fool (less so, though).

>> Or you can (be sane) and put it at no indentation:
>>
>> """
>> a_wonderful_set_of_things = {
>> ...,
>> not_missing_an_end_brace
>> }
>> """
>
> I consider that the least aesthetically pleasing, and also rather awkward:
>
>
> some_result = some_function(
> arg1, arg2, arg3, arg4,
> [item1, item2, item3, item4,
>   item5, item6, item7,
>   item8, item9, item10,
> ],
>arg6, key=spam, word=eggs,
>extras=None, foo=bar,
> )

http://xkcd.com/605/

It was obvious¹ I was talking in context of my example. I used "no
indentation" because in that case "no indentation" was correct. If you
indent line #1, it follows that other lines might well be indented to
keep style consistent.

¹ I hope. I never suggested otherwise.

Since it's not too clear for you, my usage of fool was meant
pseudoironically as a subtle reminder that it's all subjective anyway,
but that I'm also still right.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I write a script to generate 10 random EVEN numbers and write them to a .txt file?

2013-07-08 Thread Joshua Landau
On 8 July 2013 13:27, Dave Angel  wrote:
> One of your classmates has already posted the question.  However, you win
> the prize for a better subject line.  Or are you the same student, changing
> your name and wasting our time by starting a new thread.

Considering the body of the question and his GMail user icon thingy
are identical, I think that's a rigged question.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default scope of variables

2013-07-08 Thread Joshua Landau
On 8 July 2013 12:54, Neil Cerutti  wrote:
> On 2013-07-07, Steven D'Aprano  wrote:
>> On Fri, 05 Jul 2013 13:24:43 +, Neil Cerutti wrote:
>>
>>> for x in range(4):
>>>print(x)
>>> print(x) # Vader NOoOO!!!
>>
>> That loops do *not* introduce a new scope is a feature, not a bug. It is
>> *really* useful to be able to use the value of x after the loop has
>> finished.
>
> I don't buy necessarily buy that it's "*really*" useful

Just take "really" to mean "like, I'm totz not lying".

> but I do
> like introducing new names in (not really the scope of)
> if/elif/else and for statement blocks.
>
> z = record["Zip"]
> if int(z) > 9:
> zip_code = z[:-4].rjust(5, "0")
> zip4 = z[-4:]
> else:
>   zip_code = z.rjust(5, "0")
>   zip4 = ""

I'd probably break down and cry if "if"s introduced a new scope in
Pythons before the "nonlocal" keyword (assuming current Python
semantics where "=" defaults to only the inner-most scope).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Geo Location extracted from visitors ip address

2013-07-08 Thread Grant Edwards
On 2013-07-06, ?? Gr33k  wrote:
> Yes i know iam only storing the ISP's city instead of visitor's homeland 
> but this is the closest i can get:
>
> try:
>gi = pygeoip.GeoIP('/home/nikos/GeoLiteCity.dat')
>city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
>host = socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )
> except Exception as e:
>host = repr(e)
>
>
> Tried it myself and it falsey said that i'am from Europe/Athens (capital 
> of Greece) while i'am from Europe/Thessaloniki (sub-capital of Greece)
>
> If we can pin-point the uvisitor more accurately plz let me know.

For the Nth time: you can't.

-- 
Grant Edwards   grant.b.edwardsYow! HOORAY, Ronald!!
  at   Now YOU can marry LINDA
  gmail.comRONSTADT too!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Geo Location extracted from visitors ip address

2013-07-08 Thread Grant Edwards
On 2013-07-06, ?? Gr33k  wrote:
>  6/7/2013 4:41 , ??/?? ?? Gr33k :
>> Yes i know iam only storing the ISP's city instead of visitor's homeland
>> but this is the closest i can get:
>>
>> try:
>>gi = pygeoip.GeoIP('/home/nikos/GeoLiteCity.dat')
>>city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
>>host = socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )
>> except Exception as e:
>>host = repr(e)
>>
>>
>> Tried it myself and it falsey said that i'am from Europe/Athens (capital
>> of Greece) while i'am from Europe/Thessaloniki (sub-capital of Greece)
>>
>> If we can pin-point the uvisitor more accurately plz let me know.
>
> Good morning from Greece,
>
> All my Greece visitors as Dave correctly said have the ISP address which 
> here in Greece is Europe/Athens, so i have now way to distinct the 
> cities of the visitors.
>
> Is there any way to pinpoint the visitor's exact location?

No.

-- 
Grant Edwards   grant.b.edwardsYow! Does someone from
  at   PEORIA have a SHORTER
  gmail.comATTENTION span than me?
-- 
http://mail.python.org/mailman/listinfo/python-list


ipython

2013-07-08 Thread davide . dalmasso
Hi, I work with Python 3.3.
I downloaded an IPython executable version from 
http://www.lfd.uci.edu/~gohlke/pythonlibs/
I installed it but no shortcut appears in my start menu.
How can I launch it or alternatively is there some other free source of 
executable file for Windows 7?
Many Thanks



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


Re: ipython

2013-07-08 Thread Steven D'Aprano
On Mon, 08 Jul 2013 07:44:11 -0700, davide.dalmasso wrote:

> Hi, I work with Python 3.3.
> I downloaded an IPython executable version from
> http://www.lfd.uci.edu/~gohlke/pythonlibs/ I installed it but no
> shortcut appears in my start menu. How can I launch it or alternatively
> is there some other free source of executable file for Windows 7? Many
> Thanks

That's more of a Windows 7 question than a Python question. I don't know 
how to add a command to the Windows start menu.

How do you know ipython installed successfully? When you installed it, 
did you get any errors?

Try going to the Start menu, selecting the Run command, and typing 
ipython [enter].


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


Re: ipython

2013-07-08 Thread Wanderer
On Monday, July 8, 2013 10:44:11 AM UTC-4, davide@gmail.com wrote:
> Hi, I work with Python 3.3.
> 
> I downloaded an IPython executable version from 
> http://www.lfd.uci.edu/~gohlke/pythonlibs/
> 
> I installed it but no shortcut appears in my start menu.
> 
> How can I launch it or alternatively is there some other free source of 
> executable file for Windows 7?
> 
> Many Thanks

You must right click and 'run as administrator' to get the start menu shortcuts.
Otherwise, ipython.exe is in the Scripts subdirectory of your Python directory.

ie C:\Python27\Scripts
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default scope of variables

2013-07-08 Thread Joshua Landau
On 4 July 2013 05:36, Chris Angelico  wrote:
> On Thu, Jul 4, 2013 at 2:30 PM, Joshua Landau
>  wrote:
>> That said, I'm not too convinced. Personally, the proper way to do
>> what you are talking about is creating a new closure. Like:
>>
>> for i in range(100):
>> with new_scope():
>> for i in range(100):
>> func(i)
>> func(i) # Using i from original loop
>>
>> But it's not like Python'll ever support that.
>>
>
> def foo():
>   for i in range(3):
> print("outer",i)
> def inner():
>   for i in range(4):
> print("inner",i)
> inner()
> print("outer",i)
>
> That works, but you then have to declare all your nonlocals, and it
> hardly reads well.

Stealing concepts shamelessly from
http://www.slideshare.net/r1chardj0n3s/dont-do-this-24000445, you can
do this:

import inspect
from contextlib import contextmanager

@contextmanager
def scope(namespace=None):
old_names = inspect.currentframe().f_back.f_back.f_locals.copy()

yield

names = inspect.currentframe().f_back.f_back.f_locals

if namespace is not None:
new_names = {k:v for k, v in names.items() if k not in
old_names and v is not namespace}
namespace.update(**new_names)

names.clear()
names.update(old_names)

So you *can* do:

>>> for i in range(3):
... with scope():
... for i in range(3):
... print("Inner:", i)
... print("Outer", i)
Inner: 0
Inner: 1
Inner: 2
Outer 0
Inner: 0
Inner: 1
Inner: 2
Outer 1
Inner: 0
Inner: 1
Inner: 2
Outer 2

:)

If you pass scope() a dictionary, all the new variables will get added to it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread ferdy . blatsco

Hi Chris,
glad to have received your contribution, but I was expecting much more
critics...
Starting from the "little nitpick" about the comment dispositon in my
script... you are correct... It is a bad habit on my part to place
variables subjected to change at the beginning of the script... and then
forget it...
About the mistake due to replace, you gave me a perfect explanation.
Unfortunately (as probably I told you before) I will never pass to
Python 3...  Guido should not always listen only to gurus like him...
I don't like Python as before...starting from OOP and ending with codecs
like utf-8. Regarding OOP, much appreciated expecially by experts, he
could use python 2 for hiding the complexities of OOP (improving, as an
effect, object's code hiding) moving classes and objects to
imported methods, leaving in this way the programming style to the
well known old style: sequential programming and functions.
About utf-8... the same solution: keep utf-8 but for the non experts, add
methods to convert to solutions which use the range 128-255 of only one
byte (I do not give a damn about chinese and "similia"!...)
I know that is a lost battle (in italian "una battaglia persa")!

Bye, Blatt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Important features for editors

2013-07-08 Thread Sivaram Neelakantan
On Mon, Jul 08 2013,Skip Montanaro wrote:

>>> I couldn't live without the keyboard macro record and playback.
>>
>> I used to work with a programmer who couldn't live without his insulin
>> injections.
>
> Hyperbole aside, two of my most common "crutches" are Emacs macros and
> bash history.  Given how useful macros are, I find it very odd that
> recent versions of GNU Emacs dispensed with the old key binding to C-x
> c.
>
> Skip

Wasn't it C-x ( ?  From the manual

   In addition to the  and  commands described above, Emacs
also supports an older set of key bindings for defining and executing
keyboard macros.  To begin a macro definition, type `C-x ('
(`kmacro-start-macro'); as with , a prefix argument appends this
definition to the last keyboard macro.  To end a macro definition, type
`C-x )' (`kmacro-end-macro').  To execute the most recent macro, type
`C-x e' (`kmacro-end-and-call-macro').  If you enter `C-x e' while


 sivaram
 -- 

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread Chris Angelico
On Tue, Jul 9, 2013 at 3:31 AM,   wrote:
> Unfortunately (as probably I told you before) I will never pass to
> Python 3...  Guido should not always listen only to gurus like him...
> I don't like Python as before...starting from OOP and ending with codecs
> like utf-8. Regarding OOP, much appreciated expecially by experts, he
> could use python 2 for hiding the complexities of OOP (improving, as an
> effect, object's code hiding) moving classes and objects to
> imported methods, leaving in this way the programming style to the
> well known old style: sequential programming and functions.
> About utf-8... the same solution: keep utf-8 but for the non experts, add
> methods to convert to solutions which use the range 128-255 of only one
> byte (I do not give a damn about chinese and "similia"!...)
> I know that is a lost battle (in italian "una battaglia persa")!

Well, there won't be a Python 2.8, so you really should consider
moving at some point. Python 3.3 is already way better than 2.7 in
many ways, 3.4 will improve on 3.3, and the future is pretty clear.
But nobody's forcing you, and 2.7.x will continue to get
bugfix/security releases for a while. (Personally, I'd be happy if
everyone moved off the 2.3/2.4 releases. It's not too hard supporting
2.6+ or 2.7+.)

The thing is, you're thinking about UTF-8, but you should be thinking
about Unicode. I recommend you read these articles:

http://www.joelonsoftware.com/articles/Unicode.html
http://unspecified.wordpress.com/2012/04/19/the-importance-of-language-level-abstract-unicode-strings/

So long as you are thinking about different groups of characters as
different, and wanting a solution that maps characters down into the
<256 range, you will never be able to cleanly internationalize. With
Python 3.3+, you can ignore the differences between ASCII, BMP, and
SMP characters; they're all just "characters". Everything works
perfectly with Unicode.

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread ferdy . blatsco
Hi Steven,

thank you for your reply... I really needed another python guru which
is also an English teacher! Sorry if English is not my mother tongue...
"uncorrect" instead of "incorrect" (I misapplied the "similarity
principle" like "unpleasant...>...uncorrect").

Apart from these trifles, you said:
>> All characters are UTF-8, characters. "a" is a UTF-8 character. So is "ă".
Not using python 3, for me (a programmer which was present at the beginning of
computer science, badly interacting with many languages from assembler to
Fortran and from c to Pascal and so on) it was an hard job to arrange the
abrupt transition from characters only equal to bytes to some special
characters defined with 2, 3 bytes and even more.
I should have preferred another solution... but i'm not Guido!

I said:
> in the first version the utf-8 conversion to hex was shown horizontally
And you replied:
>> Oh! We're supposed to read the output *downwards*! 
You are correct, but I was only referring to "special characters"...
My main concern was compactness of output and besides that every group of
bytes used for defining "special characters" is well represented with high
nibble in the range outside ascii 0-127.

Your following observations are connected more or less to the above point
and sorry if the interpretation of output... sucks!
I think that, for the interested user, all the question is of minor
importance.

Only another point is relevant for me:
>> The loop variable just gets reset once it reaches the top of the loop
>> again.
Apart your kind observation (... "hideously ugly to read") referring to
my code snippet incrementing the loop variable... you are correct.
I will never make the same mistake!

Bye, Blatt.



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


Re: Important features for editors

2013-07-08 Thread Skip Montanaro
> Wasn't it C-x ( ?  From the manual
>
>In addition to the  and  commands described above, Emacs
> also supports an older set of key bindings for defining and executing
> keyboard macros.  To begin a macro definition, type `C-x ('
> (`kmacro-start-macro'); as with , a prefix argument appends this
> definition to the last keyboard macro.  To end a macro definition, type
> `C-x )' (`kmacro-end-macro').  To execute the most recent macro, type
> `C-x e' (`kmacro-end-and-call-macro').  If you enter `C-x e' while

(We are getting a bit off-topic, but I suppose that's not too unusual...)

Thanks for pointing that out.

Things moved around on me while I wasn't looking.  For a long, long
time, I have used C-x e as a prefix for a number of ediff commands.  I
imagine that comes from my old XEmacs habits.  C-x c was always bound
to call-last-kbd-macro, and I'm pretty sure it used to be that way in
older versions of GNU Emacs.  The kmacro package probably appeared
while I was using XEmacs.  I found that in the interim, the GNU folks
inserted all sorts of extra keys, so that many things I used to do
with two keystrokes are now done with three.  I understand the logic
of what they did (easier to increase the number of keystrokes required
for some commands than to increase the number of keys on the
keyboard), but prefer many things the way I used to do them.

So, call-last-kbd-macro got unbound in the GNU switch to kmacro, and
reasserting my preference for the way I called ediff commands meant
that the new spelling of the kmacro stuff got dropped.  I do use C-x (
and C-x ) to define macros.

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread Chris Angelico
On Tue, Jul 9, 2013 at 3:53 AM,   wrote:
>>> All characters are UTF-8, characters. "a" is a UTF-8 character. So is "ă".
> Not using python 3, for me (a programmer which was present at the beginning of
> computer science, badly interacting with many languages from assembler to
> Fortran and from c to Pascal and so on) it was an hard job to arrange the
> abrupt transition from characters only equal to bytes to some special
> characters defined with 2, 3 bytes and even more.

Even back then, bytes and characters were different. 'A' is a
character, 0x41 is a byte. And they correspond 1:1 if and only if you
know that your characters are represented in ASCII. Other encodings
(eg EBCDIC) mapped things differently. The only difference now is that
more people are becoming aware that there are more than 256 characters
in the world.

Like Magic 2014 and its treatment of Slivers, at some point you're
going to have to master the difference between bytes and characters,
or else be eternally hacking around stuff in your code, so now is as
good a time as any.

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


Re: How do I write a script to generate 10 random EVEN numbers and write them to a .txt file?

2013-07-08 Thread Dave Angel

On 07/08/2013 09:10 AM, Joshua Landau wrote:

On 8 July 2013 13:27, Dave Angel  wrote:

One of your classmates has already posted the question.  However, you win
the prize for a better subject line.  Or are you the same student, changing
your name and wasting our time by starting a new thread.


Considering the body of the question and his GMail user icon thingy
are identical, I think that's a rigged question.



I didn't notice that the actual gmail address was the same; somehow when 
I saw it prefixed by the Sanza101 and Kenz09 it looked different.


However, the body was entirely different, thoroughly rephrased.

For example, first question in each, respectively, was:

Create another function that generates a random number (You will have to 
import the relevant library to do this)


Create a function that is called from the main function, that accepts a 
number as a parameter and determines if the number is even or odd.

the next one is,



--
DaveA

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


homework + obfuscation ... this might work ...

2013-07-08 Thread Skip Montanaro
I have an idea.  Take the threads where students ask the list to do
their homework for them (but don't have the cojones to admit that's
what they are doing), and merge them with the obfuscated Python idea.
A group of people could come up with the solution off-list, then
answer the poster's original question (no fair asking them to revise
their poorly specified requirements) with a very obfuscated answer
on-list.  I think it would be interesting to be a fly on the wall when
they explain how their programs work to their professors, especially
if they have little easter eggs embedded in them.

:-)

Perhaps we could start with the 10 random even numbers?  I'll start:

#!/usr/bin/env python

import random

output = []

while len(output) < 10:
output.append(random.randrange(0, 1000, 2))

print 1, output

output = [random.randrange(0, 500) * 2 for _ in range(10)]

print 2, output

output = []

while len(output) < 10:
r = int(round(random.random() * 500))
if r % 2:
r *= 2
output.append(r)

print 3, output

getting-tired-of-homework-questions-in-my-old-age-ly, y'rs,

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


make sublists of a list broken at nth certain list items

2013-07-08 Thread CM
I'm looking for a Pythonic way to do the following:

I have data in the form of a long list of tuples.  I would like to break that 
list into four sub-lists.  The break points would be based on the nth occasion 
of a particular tuple.  (The list represents behavioral data trials; the 
particular tuple represents the break between trials; I want to collect 20 
trials at a time, so every 20th break between trials, start a new sublist).

So say I have this data:  

data_list = [(0.0, 1.0), (1.0, 24.0), (24.0, 9.0), (9.0, 17.0), (17.0, 5.0), 
(5.0, 0.0), (5.0, 0.0), (5.0, 24.0), (24.0, 13.0), (13.0, 0.0), (13.0, 21.0), 
(21.0, 0.0), (21.0, 0.0), (21.0, 23.0), (23.0, 24.0), (24.0, 10.0), (10.0, 
18.0), (18.0, 4.0), (4.0, 22.0), (22.0, 1.0), (1.0, 0.0), (1.0, 24.0), (24.0, 
6.0), (6.0, 14.0), (14.0, 5.0), (5.0, 0.0), (5.0, 0.0), (5.0, 0.0), (5.0, 0.0), 
(5.0, 0.0), (5.0, 0.0), (5.0, 0.0), (5.0, 0.0), (5.0, 0.0), (5.0, 24.0), (24.0, 
6.0), (6.0, 14.0), (14.0, 4.0), (4.0, 0.0), (4.0, 22.0), (22.0, 1.0), (1.0, 
0.0), (1.0, 24.0), (24.0, 9.0), (9.0, 17.0), (17.0, 4.0), (4.0, 0.0), (4.0, 
22.0), (22.0, 1.0), (1.0, 0.0), (1.0, 0.0), (1.0, 24.0), (24.0, 12.0), (12.0, 
4.0), (4.0, 0.0), (4.0, 22.0)]  #rest of data truncated...

I'd like to break the list into sublists at the 20th, 40th, and 60th occasions 
of any tuple that begins with 1.0--so for example, (1.0, 0.0).  This will 
produce four sub-lists, for trial 1-20, 21-40, 41-60, and 61-80.

What I have, just to get the break points within the data_list, and which is 
not working is:

trial_break_indexes_list = []  #needed to see where the sublists start
trial_count = 0  #keep count of which trial we're on

trial_break_indexes_list = []  #holds the index of the transitions_list for 
trials 1-20, 21-40, 41-60, and 61-80
trial_count = 0

for tup in data_list:
if tup[0] == 1.0: #Therefore the start of a new trial

#We have a match!  Therefore get the index in the data_list
data_list_index = data_list.index(tup)

trial_count += 1  #update the trial count.

if trial_count % 20 == 0:  #this will match on 0, 20, 40, 60, 80
trial_break_indexes_list.append(data_list_index)

print 'This is trial_break_indexes_list: ', trial_break_indexes_list

Unfortunately, the final output here is:

>>> 
This is trial_break_indexes_list:  [1, 20, 20, 20, 20, 1, 20, 1]

I sense there is a way more elegant/simpler/Pythonic way to approach this, let 
alone one that is actually correct, but I don't know of it.  Suggestions 
appreciated!

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread Dave Angel

On 07/08/2013 01:53 PM, ferdy.blat...@gmail.com wrote:

Hi Steven,

thank you for your reply... I really needed another python guru which
is also an English teacher! Sorry if English is not my mother tongue...
"uncorrect" instead of "incorrect" (I misapplied the "similarity
principle" like "unpleasant...>...uncorrect").

Apart from these trifles, you said:

All characters are UTF-8, characters. "a" is a UTF-8 character. So is "ă".

Not using python 3, for me (a programmer which was present at the beginning of
computer science, badly interacting with many languages from assembler to
Fortran and from c to Pascal and so on) it was an hard job to arrange the
abrupt transition from characters only equal to bytes to some special
characters defined with 2, 3 bytes and even more.


Characters do not have a width.  They are Unicode code points, an 
abstraction.  It's only when you encode them in byte strings that a code 
point takes on any specific width.  And some encodings go to one-byte 
strings (and get errors for characters that don't match), some go to 
two-bytes each, some variable, etc.



I should have preferred another solution... but i'm not Guido!


But Unicode has nothing to do with Guido, and it has existed for about 
25 years (if I recall correctly).  It's only that Python 3 is finally 
embracing it, and making it the default type for characters, as it 
should be.  As far as I'm concerned, the only reason it shouldn't have 
been done long ago was that programs were trying to fit on 640k DOS 
machines.  Even before Unicode, there were multi-byte encodings around 
(eg. Microsoft's MBCS), and each was thoroughly incompatible with all 
the others.  And the problem with one-byte encodings is that if you need 
to use a Greek currency symbol in a document that's mostly Norwegian (or 
some such combination of characters), there might not be ANY valid way 
to do it within a single "character set."


Python 2 supports all the same Unicode features as 3;  it's just that it 
defaults to byte strings.  So it's HARDER to get it right.


Except for special purpose programs like a file dumper, it's usually 
unnecessary for a Python 3 programmer to deal with individual bytes from 
a byte string.  Text files are a bunch of bytes, and somebody has to 
interpret them as characters.  If you let open() handle it, and if you 
give it the correct encoding, it just works.  Internally, all strings 
are Unicode, and you don't care where they came from, or what human 
language they may have characters from.  You can combine strings from 
multiple places, without much worry that they might interfere.



Windows NT/2000/XP/Vista/7 has used Unicode for its file system (NTFS) 
from the beginning (approx 1992), and has had Unicode versions of each 
of its API's for nearly as long.


I appreciate you've been around a long time, and worked in a lot of 
languages.  I've programmed professionally in at least 35 languages 
since 1967.  But we've come a long way from the 6bit characters I used 
in 1968.  At that time, we packed them 10 characters to each word.


--
DaveA

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


Re: homework + obfuscation ... this might work ...

2013-07-08 Thread Ian Kelly
On Mon, Jul 8, 2013 at 2:43 PM, Skip Montanaro  wrote:
> I have an idea.  Take the threads where students ask the list to do
> their homework for them (but don't have the cojones to admit that's
> what they are doing), and merge them with the obfuscated Python idea.
> A group of people could come up with the solution off-list, then
> answer the poster's original question (no fair asking them to revise
> their poorly specified requirements) with a very obfuscated answer
> on-list.  I think it would be interesting to be a fly on the wall when
> they explain how their programs work to their professors, especially
> if they have little easter eggs embedded in them.

You assume that the professor (or more likely, TA) will take the time
to ask them to explain the program and not just grade them down for
the extra work they had to do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: homework + obfuscation ... this might work ...

2013-07-08 Thread Skip Montanaro
> You assume that the professor (or more likely, TA) will take the time
> to ask them to explain the program and not just grade them down for
> the extra work they had to do.

Well, that would be fine too. :-)

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


Re: make sublists of a list broken at nth certain list items

2013-07-08 Thread Fábio Santos
You don't want to use index() to figure out the index of the tuples. It is
slower, and will not find the item you want if there is more than one of
the same. For example,

[1, 4, 4, 4].index(4)

will always be 1, no matter how many times you loop through it.

Instead, use enumerate() to keep track of the index. Replace your loop by:

for index, tup in enumerate(data_list):

This should fix your problem. After you have the correct indices, look into
list slicing syntax.
On 8 Jul 2013 21:59, "CM"  wrote:

> I'm looking for a Pythonic way to do the following:
>
> I have data in the form of a long list of tuples.  I would like to break
> that list into four sub-lists.  The break points would be based on the nth
> occasion of a particular tuple.  (The list represents behavioral data
> trials; the particular tuple represents the break between trials; I want to
> collect 20 trials at a time, so every 20th break between trials, start a
> new sublist).
>
> So say I have this data:
>
> data_list = [(0.0, 1.0), (1.0, 24.0), (24.0, 9.0), (9.0, 17.0), (17.0,
> 5.0), (5.0, 0.0), (5.0, 0.0), (5.0, 24.0), (24.0, 13.0), (13.0, 0.0),
> (13.0, 21.0), (21.0, 0.0), (21.0, 0.0), (21.0, 23.0), (23.0, 24.0), (24.0,
> 10.0), (10.0, 18.0), (18.0, 4.0), (4.0, 22.0), (22.0, 1.0), (1.0, 0.0),
> (1.0, 24.0), (24.0, 6.0), (6.0, 14.0), (14.0, 5.0), (5.0, 0.0), (5.0, 0.0),
> (5.0, 0.0), (5.0, 0.0), (5.0, 0.0), (5.0, 0.0), (5.0, 0.0), (5.0, 0.0),
> (5.0, 0.0), (5.0, 24.0), (24.0, 6.0), (6.0, 14.0), (14.0, 4.0), (4.0, 0.0),
> (4.0, 22.0), (22.0, 1.0), (1.0, 0.0), (1.0, 24.0), (24.0, 9.0), (9.0,
> 17.0), (17.0, 4.0), (4.0, 0.0), (4.0, 22.0), (22.0, 1.0), (1.0, 0.0), (1.0,
> 0.0), (1.0, 24.0), (24.0, 12.0), (12.0, 4.0), (4.0, 0.0), (4.0, 22.0)]
>  #rest of data truncated...
>
> I'd like to break the list into sublists at the 20th, 40th, and 60th
> occasions of any tuple that begins with 1.0--so for example, (1.0, 0.0).
>  This will produce four sub-lists, for trial 1-20, 21-40, 41-60, and 61-80.
>
> What I have, just to get the break points within the data_list, and which
> is not working is:
>
> trial_break_indexes_list = []  #needed to see where the sublists start
> trial_count = 0  #keep count of which trial we're on
>
> trial_break_indexes_list = []  #holds the index of the transitions_list
> for trials 1-20, 21-40, 41-60, and 61-80
> trial_count = 0
>
> for tup in data_list:
> if tup[0] == 1.0: #Therefore the start of a new trial
>
> #We have a match!  Therefore get the index in the data_list
> data_list_index = data_list.index(tup)
>
> trial_count += 1  #update the trial count.
>
> if trial_count % 20 == 0:  #this will match on 0, 20, 40, 60, 80
> trial_break_indexes_list.append(data_list_index)
>
> print 'This is trial_break_indexes_list: ', trial_break_indexes_list
>
> Unfortunately, the final output here is:
>
> >>>
> This is trial_break_indexes_list:  [1, 20, 20, 20, 20, 1, 20, 1]
>
> I sense there is a way more elegant/simpler/Pythonic way to approach this,
> let alone one that is actually correct, but I don't know of it.
>  Suggestions appreciated!
>
> Thanks.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: make sublists of a list broken at nth certain list items

2013-07-08 Thread Joshua Landau
On 8 July 2013 21:52, CM  wrote:
> I'm looking for a Pythonic way to do the following:
>
> I have data in the form of a long list of tuples.  I would like to break that 
> list into four sub-lists.  The break points would be based on the nth 
> occasion of a particular tuple.  (The list represents behavioral data trials; 
> the particular tuple represents the break between trials; I want to collect 
> 20 trials at a time, so every 20th break between trials, start a new sublist).

I would do this like so:

from collections import deque

# Fast and hacky -- just how I like it
exhaust_iterable = deque(maxlen=0).extend

def chunk_of(data, *, length):
count = 0
for datum in data:
count += datum[0] == 1

yield datum

if count == 60:
break

def chunked(data):
data = iter(data)
while True:
chunk = chunk_of(data, length=20)
yield chunk
exhaust_iterable(chunk)

You use "chunked(data)" and iterate over the 'chunks' in that. If you
go to the next chunk before finishing the one you're on the previous
chunk will be lost, so convert it to a permanent form first.

Looking at you code:

> for tup in data_list:
> if tup[0] == 1.0: #Therefore the start of a new trial
>
> #We have a match!  Therefore get the index in the data_list
> data_list_index = data_list.index(tup)

This is no good (ninja'd by Fábio). The proper way to keep an index is by:

for index, tup in enumerate(data_list):

> trial_count += 1  #update the trial count.
>
> if trial_count % 20 == 0:  #this will match on 0, 20, 40, 60, 80
> trial_break_indexes_list.append(data_list_index)
>
> print 'This is trial_break_indexes_list: ', trial_break_indexes_list
...
> I sense there is a way more elegant/simpler/Pythonic way to approach this, 
> let alone one that is actually correct, but I don't know of it.  Suggestions 
> appreciated!

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


Re: make sublists of a list broken at nth certain list items

2013-07-08 Thread Joshua Landau
On 8 July 2013 22:24, Joshua Landau  wrote:
> if count == 60:

Obviously this should be:

if count == length:
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: homework + obfuscation ... this might work ...

2013-07-08 Thread Joshua Landau
On 8 July 2013 21:43, Skip Montanaro  wrote:
> I have an idea.  Take the threads where students ask the list to do
> their homework for them (but don't have the cojones to admit that's
> what they are doing), and merge them with the obfuscated Python idea.
> A group of people could come up with the solution off-list, then
> answer the poster's original question (no fair asking them to revise
> their poorly specified requirements) with a very obfuscated answer
> on-list.  I think it would be interesting to be a fly on the wall when
> they explain how their programs work to their professors, especially
> if they have little easter eggs embedded in them.
>
> :-)
>
> Perhaps we could start with the 10 random even numbers?  I'll start:

You're doing it wrong:

def getRandomNumbers() -> [int]:
return [4]*10;  # chosen by fair dice roll
# guaranteed to be random

#!/too/famous/to_need/a.reference
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread MRAB

On 08/07/2013 21:56, Dave Angel wrote:

On 07/08/2013 01:53 PM, ferdy.blat...@gmail.com wrote:

Hi Steven,

thank you for your reply... I really needed another python guru which
is also an English teacher! Sorry if English is not my mother tongue...
"uncorrect" instead of "incorrect" (I misapplied the "similarity
principle" like "unpleasant...>...uncorrect").

Apart from these trifles, you said:

All characters are UTF-8, characters. "a" is a UTF-8 character. So is "ă".

Not using python 3, for me (a programmer which was present at the beginning of
computer science, badly interacting with many languages from assembler to
Fortran and from c to Pascal and so on) it was an hard job to arrange the
abrupt transition from characters only equal to bytes to some special
characters defined with 2, 3 bytes and even more.


Characters do not have a width.

[snip]

It depends what you mean by "width"! :-)

Try this (Python 3):

>>> print("A\N{FULLWIDTH LATIN CAPITAL LETTER A}")
AA

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread Chris Angelico
On Tue, Jul 9, 2013 at 6:56 AM, Dave Angel  wrote:
> But Unicode has nothing to do with Guido, and it has existed for about 25
> years (if I recall correctly).

Depends how you measure. According to [1], the work kinda began back
then (25 years ago being 1988), but it wasn't till 1991/92 that the
spec was published. Also, the full Unicode range with multiple planes
came about in 1996, with Unicode 2.0, so that could also be considered
the beginning of Unicode. But that still means it's nearly old enough
to drink, so programmers ought to be aware of it.

[1] http://en.wikipedia.org/wiki/Unicode#History

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread Joshua Landau
On 8 July 2013 22:38, MRAB  wrote:
> On 08/07/2013 21:56, Dave Angel wrote:
>> Characters do not have a width.
>
> [snip]
>
> It depends what you mean by "width"! :-)
>
> Try this (Python 3):
>
 print("A\N{FULLWIDTH LATIN CAPITAL LETTER A}")
> AA

Serious question: How would one find the width of a character by that
definition?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread Dave Angel

On 07/08/2013 05:49 PM, Chris Angelico wrote:

On Tue, Jul 9, 2013 at 6:56 AM, Dave Angel  wrote:

But Unicode has nothing to do with Guido, and it has existed for about 25
years (if I recall correctly).


Depends how you measure. According to [1], the work kinda began back
then (25 years ago being 1988), but it wasn't till 1991/92 that the
spec was published. Also, the full Unicode range with multiple planes
came about in 1996, with Unicode 2.0, so that could also be considered
the beginning of Unicode. But that still means it's nearly old enough
to drink, so programmers ought to be aware of it.



Well, then I'm glad I stuck the qualifier on it.  I remember where I was 
working, and that company folded in 1992.  I was working on NT long 
before its official release in 1993, and it used Unicode, even if the 
spec was sliding along.  I'm sure I got unofficial versions of things 
through Microsoft, at the time.




--
DaveA

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


Re: Editor Ergonomics [was: Important features for editors]

2013-07-08 Thread Rhodri James

On Sat, 06 Jul 2013 16:04:00 +0100, rusi  wrote:


On Saturday, July 6, 2013 7:40:39 PM UTC+5:30, Skip Montanaro wrote:

* a lot of typing,
* use of modifier keys (ctrl, alt, command, etc)
* movement between the mouse and the keyboard


My own experience: The second 2 are the worse culprits.
And while emacs is bad on the second, its excellent on the third -- to  
the extend that you 'live inside emacs,' you dont need the mouse.


You clearly never trained as a classical pianist :-)

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread Chris Angelico
On Tue, Jul 9, 2013 at 8:45 AM, Dave Angel  wrote:
> On 07/08/2013 05:49 PM, Chris Angelico wrote:
>>
>> On Tue, Jul 9, 2013 at 6:56 AM, Dave Angel  wrote:
>>>
>>> But Unicode has nothing to do with Guido, and it has existed for about 25
>>> years (if I recall correctly).
>>
>>
>> Depends how you measure. According to [1], the work kinda began back
>> then (25 years ago being 1988), but it wasn't till 1991/92 that the
>> spec was published. Also, the full Unicode range with multiple planes
>> came about in 1996, with Unicode 2.0, so that could also be considered
>> the beginning of Unicode. But that still means it's nearly old enough
>> to drink, so programmers ought to be aware of it.
>>
>
> Well, then I'm glad I stuck the qualifier on it.  I remember where I was
> working, and that company folded in 1992.  I was working on NT long before
> its official release in 1993, and it used Unicode, even if the spec was
> sliding along.  I'm sure I got unofficial versions of things through
> Microsoft, at the time.

No doubt! Of course, this list is good at dealing with the hard facts
and making sure the archives are accurate, but that doesn't change
your memory.

Anyway, your fundamental point isn't materially affected by whether
Unicode is 17 or 25 years old. It's been around plenty long enough by
now, we should use it. Same with IPv6, too...

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


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread MRAB

On 08/07/2013 23:02, Joshua Landau wrote:

On 8 July 2013 22:38, MRAB  wrote:

On 08/07/2013 21:56, Dave Angel wrote:

Characters do not have a width.


[snip]

It depends what you mean by "width"! :-)

Try this (Python 3):


print("A\N{FULLWIDTH LATIN CAPITAL LETTER A}")

AA


Serious question: How would one find the width of a character by that
definition?


>>> import unicodedata
>>> unicodedata.east_asian_width("A")
'Na'
>>> unicodedata.east_asian_width("\N{FULLWIDTH LATIN CAPITAL LETTER A}")
'F'

The possible widths are:

N  = Neutral
A  = Ambiguous
H  = Halfwidth
W  = Wide
F  = Fullwidth
Na = Narrow

All you then need to do is find out what those actually mean...

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


Re: UnpicklingError: NEWOBJ class argument isn't a type object

2013-07-08 Thread skunkwerk
On Monday, July 8, 2013 12:45:55 AM UTC-7, Peter Otten wrote:
> skunkwerk wrote:
> 
> 
> 
> > Hi,
> 
> >   I'm using a custom pickler that replaces any un-pickleable objects (such
> 
> >   as sockets or files) with a string representation of them, based on the
> 
> >   code from Shane Hathaway here:
> 
> > http://stackoverflow.com/questions/4080688/python-pickling-a-dict-with-
> 
> some-unpicklable-items
> 
> > 
> 
> > It works most of the time, but when I try to unpickle a Django
> 
> > HttpResponse, I get the following error: UnpicklingError: NEWOBJ class
> 
> > argument isn't a type object
> 
> > 
> 
> > I have no clue what the error actually means.  If it pickles okay, why
> 
> > should it not be able to unpickle?  Any ideas?
> 
> 
> 
> A simple way to provoke the error is to rebind the name referring to the 
> 
> class of the pickled object:
> 
> 
> 
> >>> import cPickle
> 
> >>> class A(object): pass
> 
> ... 
> 
> >>> p = cPickle.dumps(A(), -1)
> 
> >>> cPickle.loads(p)
> 
> <__main__.A object at 0x7fce7bb58c50>
> 
> >>> A = 42
> 
> >>> cPickle.loads(p)
> 
> Traceback (most recent call last):
> 
>   File "", line 1, in 
> 
> cPickle.UnpicklingError: NEWOBJ class argument isn't a type object
> 
> 
> 
> You may be doing something to that effect.

Hey Peter,
  I tried unpickling even from another file with no other code in it, but came 
up with the same error - so I don't think it's a rebinding issue.

But I got the error to disappear when I removed the "hasattr(obj, 
'__getstate__')" from this line of code in the persistent_id function:
if not hasattr(obj, '__getstate__') and isinstance(obj,(basestring, bool, int, 
long, float, complex, tuple, list, set, dict)):
return ["filtered:%s" % type(obj)]

When I do that, I get a few more FilteredObjects in the result, for things like:



I figured these classes must have __getstate__ methods which leads to them 
being pickled without a persistent_id (it turns out they actually have __repr__ 
methods).

So these classes get pickled fine, but run into problems when trying to 
unpickle them.  I understand why ImportErrors would happen if the necessary 
modules haven't been loaded, but this NEWOBJ error is still kind of mystifying.
I guess I just won't pickle any classes for now, if unpickling them is going to 
be dicey.

thanks for the help guys,
imran
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A small question about PEP 8

2013-07-08 Thread Ethan Furman

On 07/08/2013 03:39 AM, Joshua Landau wrote:

On 8 July 2013 00:32, Xue Fuqiao  wrote:

Hi all,

(English is not my native language; please excuse typing errors.)

I'm a Python newbie and just started reading PEP 8.  PEP says:

---
|The closing brace/bracket/parenthesis on multi-line constructs may
|either line up under the last item of the list, as in:
|
|my_list = [
|1, 2, 3,
|4, 5, 6,
|]
|result = some_function_that_takes_arguments(
|'a', 'b', 'c',
|'d', 'e', 'f',
|)
---

I think the last item in my_list/result is 6/'f', respectively.  So why
doesn't the bracket/paren line up _under_ the last item?  ISTM the code
isn't consistent with the description.

I have searched the archive of c.l.p and the web, but nothing helped.
Can anyone point me in the right direction?


You will grow to be a wonderful pedant. What it means is that the
indentation will match the last one. Imagine:

"""
a_wonderful_set_of_things = {
 bannanas_made_of_apples,
 chocolate_covered_horns,
 doors_that_slide,
 china_but_on_the_moon,
 buffalo_with_windy_hair,
 not_missing_an_end_brace
"""¹

Now, there are several places you can put the end brace. You can (be a
massive fool and) put it after the last item:

"""
a_wonderful_set_of_things = {
 ...,
 not_missing_an_end_brace}
"""

You can also (be a fool and) put it at the same *indentation*:

"""
a_wonderful_set_of_things = {
 ...,
 not_missing_an_end_brace
 }
"""


Not only a fool but a crazy fool!  That next-to-last line should have a comma!

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


the general development using Python

2013-07-08 Thread ajetrumpet
all,

I am unhappy with the general Python documentation and tutorials.  I have 
worked with Python very little and I'm well aware of the fact that it is a 
lower-level language that integrates with the shell.

I came from a VB legacy background and I've already "un-learned" everything 
that I need to (I know, that language stinks, and isn't OOP or even useful!).

I have to get back into writing Python but I'm lacking one thing ... a general 
understanding of how to write applications that can be deployed (either in .exe 
format or in other formats).

So my issue is basically to understand how to go about writing programs and 
compiling them so they can be deployed to less tech-savvy people.  Here's what 
I think I have to do, in a general sense:

=> Pick a GUI and just run through the tutorials to learn the interfaces as 
fast as possible.

This is all fine and dandy, but more than likely when I do this the people that 
I am sending solutions to will, if not receiving a simple .exe file, receive 
the package from me and say to themselves "what in the world do I do with 
this!?"

Is there anyway you guys would suggest that I fix this or help them deal with 
complex languages like Python and programs written with it?

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


Re: the general development using Python

2013-07-08 Thread Joshua Landau
On 9 July 2013 02:45,   wrote:
> all,
>
> I am unhappy with the general Python documentation and tutorials.  I have 
> worked with Python very little and I'm well aware of the fact that it is a 
> lower-level language that integrates with the shell.
>
> I came from a VB legacy background and I've already "un-learned" everything 
> that I need to (I know, that language stinks, and isn't OOP or even useful!).
>
> I have to get back into writing Python but I'm lacking one thing ... a 
> general understanding of how to write applications that can be deployed 
> (either in .exe format or in other formats).
>
> So my issue is basically to understand how to go about writing programs and 
> compiling them so they can be deployed to less tech-savvy people.  Here's 
> what I think I have to do, in a general sense:
>
> => Pick a GUI and just run through the tutorials to learn the interfaces as 
> fast as possible.
>
> This is all fine and dandy, but more than likely when I do this the people 
> that I am sending solutions to will, if not receiving a simple .exe file, 
> receive the package from me and say to themselves "what in the world do I do 
> with this!?"
>
> Is there anyway you guys would suggest that I fix this or help them deal with 
> complex languages like Python and programs written with it?

You cannot compile Python in any meaningful way that does what you want.

There are projects that "bundle" the CPython interpreter with your
project, but this makes those files really big. I suggest just making
sure that Python is installed on their end - it's a one-time thing
anyway.

You don't expect to be able to run Javascript without a Javascript
interpreter (such as a browser) so why would you expect differently
for Python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the general development using Python

2013-07-08 Thread Chris Angelico
On Tue, Jul 9, 2013 at 11:45 AM,   wrote:
> I have to get back into writing Python but I'm lacking one thing ... a 
> general understanding of how to write applications that can be deployed 
> (either in .exe format or in other formats).

That's one last thing you need to un-learn, then :)

You distribute Python applications simply as they are - as a .py file
(or a collection of .py files), and your users run them. It's really
that simple!

In fact, deploying to .exe or equivalent would restrict your users to
those running a compatible OS (same OS, same word/pointer size (32-bit
or 64-bit), possibly other restrictions too), whereas deploying the
.py files just requires that they have a compatible Python interpreter
installed. Target the three most popular desktop platforms all at
once, no Linux/Windows/Mac OS versioning. Target the lesser-known
platforms like OS/2 with the same script. And completely eliminate the
"compile step", which might take a long time with large projects.
(Okay, your code does still get compiled, but the interpreter manages
all that for you. All you need to know is that the .pyc files don't
need to be distributed.)

Python - like most other modern high level languages - is designed to
save you the hassle of working with the details. This is another of
those hassle-savings. :)

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


Re: the general development using Python

2013-07-08 Thread Joel Goldstick
On Mon, Jul 8, 2013 at 9:45 PM,  wrote:

> all,
>
> I am unhappy with the general Python documentation and tutorials.  I have
> worked with Python very little and I'm well aware of the fact that it is a
> lower-level language that integrates with the shell.
>
> I came from a VB legacy background and I've already "un-learned"
> everything that I need to (I know, that language stinks, and isn't OOP or
> even useful!).
>
> I have to get back into writing Python but I'm lacking one thing ... a
> general understanding of how to write applications that can be deployed
> (either in .exe format or in other formats).
>
> So my issue is basically to understand how to go about writing programs
> and compiling them so they can be deployed to less tech-savvy people.
>  Here's what I think I have to do, in a general sense:
>
> => Pick a GUI and just run through the tutorials to learn the interfaces
> as fast as possible.
>
> This is all fine and dandy, but more than likely when I do this the people
> that I am sending solutions to will, if not receiving a simple .exe file,
> receive the package from me and say to themselves "what in the world do I
> do with this!?"
>
> Is there anyway you guys would suggest that I fix this or help them deal
> with complex languages like Python and programs written with it?
>
> thanks guys.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Why do you want to use python?  It isn't a language that can be packaged as
an executable.  Who are these people who you make software for who need to
have a single file?

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Editor Ergonomics [was: Important features for editors]

2013-07-08 Thread Jason Friedman
I am right-handed and use a lefty-mouse about 50% of the time.
It was difficult at first, now I'm almost as fast lefty as righty.
As has been stated by others, changing the muscles being used reduces the
impact on any one of them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the general development using Python

2013-07-08 Thread CM
On Monday, July 8, 2013 9:45:16 PM UTC-4, ajetr...@gmail.com wrote:
> all,
> 
> 
> 
> I am unhappy with the general Python documentation and tutorials.  

OK.  Do you mean the official Python.org docs?  Which tutorials?  There's a ton 
out there.

> I have worked with Python very little and I'm well aware of the fact that it 
> is a lower-level language that integrates with the shell.

I thought it was a high level language. Integrates with the shell?  Isn't it 
just simplest to think of it as a programming language and that's what you need 
to know?


> I came from a VB legacy background and I've already "un-learned" everything 
> that I need to (I know, that language stinks, and isn't OOP or even useful!).

On that last point, I think a quick Google search of job postings suggests 
otherwise.

> I have to get back into writing Python but I'm lacking one thing ... 

I'm guessing it is probably more than *one* thing.  But moving along...

> So my issue is basically to understand how to go about writing programs and 
> compiling them so they can be deployed to less tech-savvy people.  Here's 
> what I think I have to do, in a general sense:
> 
> => Pick a GUI and just run through the tutorials to learn the interfaces as 
> fast as possible.

Yes.

> This is all fine and dandy, but more than likely when I do this the people 
> that I am sending solutions to will, if not receiving a simple .exe file, 
> receive the package from me and say to themselves "what in the world do I do 
> with this!?"

Yes. If they are not Python users, that's right.  
 
> Is there anyway you guys would suggest that I fix this or help them deal with 
> complex languages like Python and programs written with it?

Again, "complex language"?  It's a programming language, that's it.

Anyway, yes: read the first sentence after "Overview" here:
https://us.pycon.org/2012/schedule/presentation/393/

The other respondents to your post have a good philosophical point, that it is 
kind of unfortunate to bundle up a Python program and the whole interpreter 
when you can just send a much smaller .py file, but in reality, there are a 
number of cases where doing it is preferred.  First, your case with completely 
unPython-savvy users.  Second, if you have a lot of dependencies and it would 
make it necessary for end users to install all of them for your program to 
work.  

In the end, I'm a fan of them.  Couple of responses to others in that regard:

> There are projects that "bundle" the CPython interpreter with your
> project, but this makes those files really big.

Maybe 5-20 MB.  That's a lot bigger than a few hundred K, but it's not that 
important to keep size down, really.

>  Target the three most popular desktop platforms all at once, no 
> Linux/Windows/Mac OS versioning. 

Ehhh... There are differences, in, e.g., wxPython between the three platforms, 
and you can either do different versions or, more aptly, just fix these 
differences in your code with conditional statements ("if this is Win, do this, 
else do that").

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


looking for a new router

2013-07-08 Thread saadharana
Hey i'm looking for a new router. I have no set budget. Only US stores. I
have cable internet and few laptops connected to it so it needs to have a
strong wireless internet signal. Also i do gaming as well on wireless
internet and download many large files. Thank you for the help. 



-
used computers in chennai 
--
View this message in context: 
http://python.6.x6.nabble.com/looking-for-a-new-router-tp5024178.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Networked Printer Issues

2013-07-08 Thread saadharana
Hey All,

I just built a new PC and networked the printer (just like w/the old setup)
but it doesn't seem to work.. I remember when I did it last time it took all
of 1 minute to setup but this time the troubleshooting is going on days of
my spare time. I'd really like to just get this working.



-
used computers in chennai 
--
View this message in context: 
http://python.6.x6.nabble.com/Networked-Printer-Issues-tp5024177.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Strange networking problems

2013-07-08 Thread saadharana
I have two computers connected through a router, one via cable and running
XP, the other via wireless running win 7. This network was set up a while
back and then not used for a long time, but at one point it was working, now
there seem to be some sort of problems.



-
used computers in chennai 
--
View this message in context: 
http://python.6.x6.nabble.com/Strange-networking-problems-tp5024179.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default scope of variables

2013-07-08 Thread alex23

On 7/07/2013 11:43 PM, Chris Angelico wrote:

Yep. There's a problem, though, when you bring in subtransactions. The
logic wants to be like this:

with new_transaction(conn) as tran:
 tran.query("blah")
 with tran.subtransaction() as tran:
 tran.query("blah")
 with tran.subtransaction() as tran:
 tran.query("blah")
 # roll this subtransaction back
 tran.query("blah")
 tran.commit()
 tran.query("blah")
 tran.commit()

The 'with' statement doesn't allow this.


I'd take the 'explicit is better than implicit' approach to naming the
context managers here and rather than use 'tran' choose names that
reflect for what the transaction is to be used ie summarising what's in
the "blah" of each query.

with new_transaction(conn) as folder_tran:
folder_tran.query("blah")
with folder_tran.subtransaction() as file_tran:
file_tran.query("blah")
with file_tran.subtransaction() as type_tran:
type_tran.query("blah")

(for want of a better heirachical example...)
--
http://mail.python.org/mailman/listinfo/python-list


crack a router passcode

2013-07-08 Thread saadharana
I need to crack my router passcode to see what firmware it's running. There's
a passcode set but I don't remember it and it's not written down anywhere.




-
used computers in chennai 
--
View this message in context: 
http://python.6.x6.nabble.com/crack-a-router-passcode-tp5024180.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for a new router

2013-07-08 Thread Chris Angelico
On Tue, Jul 9, 2013 at 2:52 PM, saadharana  wrote:
> Hey i'm looking for a new router. I have no set budget. Only US stores. I
> have cable internet and few laptops connected to it so it needs to have a
> strong wireless internet signal. Also i do gaming as well on wireless
> internet and download many large files. Thank you for the help.

I recommend you go to a small local store that has friendly people and
real service, tell them what you're needing, and support local
business with your custom. That'll be more helpful to you than asking
on a mailing list that's about Python. :)

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


RAM slots problem

2013-07-08 Thread saadharana
I've got some annoying problem with RAM. I was depth cleaning my case,
everything regular, it wasn't my first time. And when I put it all together
and powered it on, it wasn't working, just beeps fast. But how that happend
when I put all back in like it was before?? Later I realised that problem
was in position of RAM sticks. I still can't understand what happend, but
now computer won't work on every RAM position, and especially not like it
was before. 



-
used computers in chennai 
--
View this message in context: 
http://python.6.x6.nabble.com/RAM-slots-problem-tp5024183.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Need to build a server computer

2013-07-08 Thread saadharana
Hey, I'm in a bit of a dilemma and I need help. I need to host 2 or 3
Minecraft servers for a fellow gamer and I. However, I am not sure how much
memory or what general kind of processor to get. Obviously, I won't need a
lot of graphics power or hard drive space for a basic server, but I'm still
stuck. It will most likely be running Windows 7 x64, and the max player
count will not be more than 20 on each server. Any suggestions?




-
used computers in chennai 
--
View this message in context: 
http://python.6.x6.nabble.com/Need-to-build-a-server-computer-tp5024182.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default scope of variables

2013-07-08 Thread Chris Angelico
On Tue, Jul 9, 2013 at 2:52 PM, alex23  wrote:
> with new_transaction(conn) as folder_tran:
> folder_tran.query("blah")
> with folder_tran.subtransaction() as file_tran:
> file_tran.query("blah")
> with file_tran.subtransaction() as type_tran:
> type_tran.query("blah")

Warp my code around a language limitation? Only if I absolutely have to.

The subtransactions are NOT concepted as separate transactions. They
are effectively the database equivalent of a try/except block. Would
you want to have to use a different name for a builtin just because
you're inside a try block?

a = int("123")
try:
b = int1(user_input)
except ValueError:
b = 0
c = int("234")

No. That assignment to b should be int(), same as a and c.

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


Re: the general development using Python

2013-07-08 Thread Chris Angelico
On Tue, Jul 9, 2013 at 2:46 PM, CM  wrote:
>>  Target the three most popular desktop platforms all at once, no
>> Linux/Windows/Mac OS versioning.
>
> Ehhh... There are differences, in, e.g., wxPython between the three 
> platforms, and you can either do different versions or, more aptly, just fix 
> these differences in your code with conditional statements ("if this is Win, 
> do this, else do that").

Please watch your citations, you quoted several different people
without any hint as to who said what :)

Yes, there are a few differences. But a *lot* less than there are
differences between a Linux executable and a Windows one, or between
32-bit and 64-bit binaries, or between Red Hat and Debian packages,
etc, etc, etc. Differences in windowing systems or newlines or path
separators will need to be dealt with regardless of the app, but there
are a whole pile of additional differences when you distribute binary
executables.

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


USB wont format?

2013-07-08 Thread saadharana
Hi guys; i have here a Scandisk Usb that i formatted it to f32 and tried to
use on Linux did not work now i'm trying to use it on windows and it says i
have to format and i go format it and it wont format .



-
used computers in chennai 
--
View this message in context: 
http://python.6.x6.nabble.com/USB-wont-format-tp5024186.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re-using my SSD drive?

2013-07-08 Thread saadharana
Hi guys,

So I heard that once your SSD is installed with windows with a new
motherboard, it will be stuck with it forever?

So does that mean SSDs and HDDs are pretty much not-recyclable?

Thanks in advance 



-
used computers in chennai 
--
View this message in context: 
http://python.6.x6.nabble.com/Re-using-my-SSD-drive-tp5024184.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to Clone a Hard Drive

2013-07-08 Thread saadharana
I just recently realized that my laptop's hard drive was going down the road
to failure, so I had to clone all the data from the old drive onto a new
drive from Newegg. Since I have all the steps fresh in my mind, I figured
I'd write a guide on how to clone a hard drive.



-
used computers in chennai 
--
View this message in context: 
http://python.6.x6.nabble.com/How-to-Clone-a-Hard-Drive-tp5024185.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for a new router

2013-07-08 Thread Dotan Cohen
On Tue, Jul 9, 2013 at 7:57 AM, Chris Angelico  wrote:
> I recommend you go to a small local store that has friendly people and
> real service, tell them what you're needing, and support local
> business with your custom. That'll be more helpful to you than asking
> on a mailing list that's about Python. :)
>
> ChrisA

Chris, the account that you replied to is just a spam account for his
link at the bottom. Helpfully, it appears that Nabble has removed the
link and left only the text.

--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for a new router

2013-07-08 Thread Chris Angelico
On Tue, Jul 9, 2013 at 3:27 PM, Dotan Cohen  wrote:
> On Tue, Jul 9, 2013 at 7:57 AM, Chris Angelico  wrote:
>> I recommend you go to a small local store that has friendly people and
>> real service, tell them what you're needing, and support local
>> business with your custom. That'll be more helpful to you than asking
>> on a mailing list that's about Python. :)
>>
>> ChrisA
>
> Chris, the account that you replied to is just a spam account for his
> link at the bottom. Helpfully, it appears that Nabble has removed the
> link and left only the text.

Yes, I guessed that when the great spew of them started coming
through. This was the first, so I thought it a legitimate (but
mis-directed) post.

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


Re: ipython

2013-07-08 Thread alex23

On 9/07/2013 12:44 AM, davide.dalma...@gmail.com wrote:

Hi, I work with Python 3.3.
I downloaded an IPython executable version from 
http://www.lfd.uci.edu/~gohlke/pythonlibs/
I installed it but no shortcut appears in my start menu.
How can I launch it or alternatively is there some other free source of 
executable file for Windows 7?


The IPython installer actually mentions this when it finishes
installing:

"Distribute (setuptools) is required to create Start Menu items.
Re-run this installer after installing distribute to get Start
Menu items."

You can grab the setup for distribute from:

http://python-distribute.org/distribute_setup.py

If your Python 3.3 installation is part of your PATH, you simply do:

python3 distribute_setup.py install

When it's finished, run the IPython installer again and you'll find
it now creates a start menu shortcut for you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Default scope of variables

2013-07-08 Thread alex23

On 9/07/2013 3:07 PM, Chris Angelico wrote:

The subtransactions are NOT concepted as separate transactions. They
are effectively the database equivalent of a try/except block.


Sorry, I assumed each nested query was somehow related to the prior
one. In which case, I'd probably go with Ethan's suggestion of a
top-level transaction context manager with its own substransaction
method.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Default scope of variables

2013-07-08 Thread Chris Angelico
On Tue, Jul 9, 2013 at 4:08 PM, alex23  wrote:
> On 9/07/2013 3:07 PM, Chris Angelico wrote:
>>
>> The subtransactions are NOT concepted as separate transactions. They
>> are effectively the database equivalent of a try/except block.
>
>
> Sorry, I assumed each nested query was somehow related to the prior
> one. In which case, I'd probably go with Ethan's suggestion of a
> top-level transaction context manager with its own substransaction
> method.

Yeah, that would probably be the best option in this particular
instance. Though I do still like the ability to have variables shadow
each other, even if there's a way around one particular piece of code
that uses the technique.

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


Re: looking for a new router

2013-07-08 Thread Steven D'Aprano
On Mon, 08 Jul 2013 21:52:19 -0700, saadharana wrote:

> Hey i'm looking for a new router. 

I recommend this one:

http://www.bunnings.com.au/products_product_1350w-aeg-12-router-rt1350e_P6230066.aspx


Helpfully-as-ever-ly yrs,



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


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread Steven D'Aprano
On Tue, 09 Jul 2013 00:32:00 +0100, MRAB wrote:

> On 08/07/2013 23:02, Joshua Landau wrote:
>> On 8 July 2013 22:38, MRAB  wrote:
>>> On 08/07/2013 21:56, Dave Angel wrote:
 Characters do not have a width.
>>>
>>> [snip]
>>>
>>> It depends what you mean by "width"! :-)
>>>
>>> Try this (Python 3):
>>>
>> print("A\N{FULLWIDTH LATIN CAPITAL LETTER A}")
>>> AA
>>
>> Serious question: How would one find the width of a character by that
>> definition?
>>
>  >>> import unicodedata
>  >>> unicodedata.east_asian_width("A")
> 'Na'
>  >>> unicodedata.east_asian_width("\N{FULLWIDTH LATIN CAPITAL LETTER
>  >>> A}")
> 'F'
> 
> The possible widths are:
> 
>  N  = Neutral
>  A  = Ambiguous
>  H  = Halfwidth
>  W  = Wide
>  F  = Fullwidth
>  Na = Narrow
> 
> All you then need to do is find out what those actually mean...

In some East-Asian encodings, there are code-points for Latin characters 
in two forms: "half-width" and "full-width". The half-width form took up 
a single fixed-width column; the full-width forms took up two fixed-width 
columns, so they would line up nicely in columns with Asian characters.

See also:

http://www.unicode.org/reports/tr11/

and search Wikipedia for "full-width" and "half-width".


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


Re: hex dump w/ or w/out utf-8 chars

2013-07-08 Thread Steven D'Aprano
On Tue, 09 Jul 2013 07:49:45 +1000, Chris Angelico wrote:

> On Tue, Jul 9, 2013 at 6:56 AM, Dave Angel  wrote:
>> But Unicode has nothing to do with Guido, and it has existed for about
>> 25 years (if I recall correctly).
> 
> Depends how you measure. According to [1], the work kinda began back
> then (25 years ago being 1988), but it wasn't till 1991/92 that the spec
> was published. Also, the full Unicode range with multiple planes came
> about in 1996, with Unicode 2.0, so that could also be considered the
> beginning of Unicode. But that still means it's nearly old enough to
> drink, so programmers ought to be aware of it.

Yes, yes, a thousand times yes. It's really not that hard to get the 
basics of Unicode.

"When I discovered that the popular web development tool PHP has almost 
complete ignorance of character encoding issues, blithely using 8 bits 
for characters, making it darn near impossible to develop good 
international web applications, I thought, enough is enough.

So I have an announcement to make: if you are a programmer working in 
2003 and you don't know the basics of characters, character sets, 
encodings, and Unicode, and I catch you, I'm going to punish you by 
making you peel onions for 6 months in a submarine. I swear I will."

http://www.joelonsoftware.com/articles/Unicode.html

Also: http://nedbatchelder.com/text/unipain.html




To start with, if you're writing code for Python 2.x, and not using u'' 
for strings, then you're making a rod for your own back. Do yourself a 
favour and get into the habit of always using u'' strings in Python 2.


I'll-start-taking-my-own-advice-next-week-I-promise-ly yrs,



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