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

2013-07-04 Thread Νίκος

Στις 4/7/2013 8:44 πμ, ο/η ru...@yahoo.com έγραψε:

On 07/03/2013 09:07 PM, rusi wrote:

[...]
I got into it because I felt Chris had done more service to Nikos and
the list than others and then was being misrepresented.


I don't know why you think I misrepresented him.  I questioned
the morality of his accepting access to Nikos' server and then
doing what he did.  If you think it is a black-and-white question
then you are welcome to your opinion but you are wrong.  Somebody
needed to point out the other side even if it happens to be a
minority opinion here.

Those actions of Chris and their morality are independent of
any other help he did or did not provide Nikos which is why I
clipped that part.  (For the record I could post links to a
number of distinctly unhelpful posts Chris also made to Nikos
but I am not disputing in general Chris' efforts here.)


Actually Chris's way of responding is by giving me general hints or urls 
to look into and not provide relevant code to show me my errors or 
specific instructions on what needs to be done to solve something.


And yes, since he didn't wanted to help he should have stated clearly 
that helping me by looking my code wasn't into his intentions.


Thus, he shouldn't have logged on to my server.


--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Default scope of variables

2013-07-04 Thread Peter Otten
Steven D'Aprano wrote:

 Well, if I ever have more than 63,000,000 variables[1] in a function,
 I'll keep that in mind. Until then, I'm pretty sure you can trivially
 avoid name clashes with globals that you wish to avoid clashing with.

 [1] Based on empirical evidence that Python supports names with length at
 least up to one million characters long, and assuming that each character
 can be an ASCII letter, digit or underscore.

That would be 63**10**6. Or 53*63**99 if I were to nitpick... 


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


Re: Default scope of variables

2013-07-04 Thread Ian Kelly
On Wed, Jul 3, 2013 at 11:32 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Python lets you do that across but not within functions.

 But Javascript/ECMAScript/whatever doesn't give you that. A var
 declaration makes it function-local, no matter where the declaration is.
 That's pointless. C++, on the other hand, lets you do this:

 void somefunc() {
 for (int i=0;i10;++i) {
 // do something with outer i
 for (int i=0;i4;++i) {
 // do something with inner i
 }
 // outer i is visible again
 }
 // neither i is visible
 }

 That's truly horrible. If the cost of this flexibility is that I'll
 have to read, and debug, other people's code with this sort of thing, I'm
 happy to be less flexible. For what possible reason other than because I
 can would you want to use the same loop variable name in two nested
 loops?

It's interesting to note that while Java and C# also allow reuse of
local variable names, they do not allow local variables declared in
inner scopes to shadow variables declared in enclosing scopes, as in
the example above.  But the following would be perfectly legal:

void somefunc() {
for (int i = 0; i  a.size; ++i) {
// do something with a[i]
}
for (int i = 0; i  b.size; ++i) {
// do something with b[i]
}
}

And the two i's are treated as completely separate variables here, as
arguably they should be since they're used for two distinct purposes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Important features for editors

2013-07-04 Thread cutems93
I am researching on editors for my own reference. I found that each of them has 
some features that other don't, but I am not sure which features are 
significant/necessary for a GOOD editor. What features do you a good editor 
should have? Keyboard shortcuts? Extensions?

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


Re: Default scope of variables

2013-07-04 Thread Dave Angel

On 07/04/2013 01:32 AM, Steven D'Aprano wrote:



  SNIP


Well, if I ever have more than 63,000,000 variables[1] in a function,
I'll keep that in mind.


SNIP


[1] Based on empirical evidence that Python supports names with length at
least up to one million characters long, and assuming that each character
can be an ASCII letter, digit or underscore.



Well, the number wouldn't be 63,000,000.  Rather it'd be 63**100

I probably have it wrong, but I think that looks like:

859,122,207,646,748,720,415,212,786,780,258,721,683,540,870,960,267,706,738,947,655,539,422,295,787,680,882,091,181,482,626,114,653,152,637,456,091,641,990,601,474,111,018,521,295,858,424,750,289,461,372,414,431,396,326,232,796,267,104,001

variables.  (The number has 180 digits)

--
DaveA


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


Re: Important features for editors

2013-07-04 Thread Νίκος

Στις 4/7/2013 10:32 πμ, ο/η cutems93 έγραψε:

I am researching on editors for my own reference. I found that each of them has 
some features that other don't, but I am not sure which features are 
significant/necessary for a GOOD editor. What features do you a good editor 
should have? Keyboard shortcuts? Extensions?

Thanks!
Min


Download Sublime Text v3

Is a great editor

--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Access Violation Error while using Python Ctypes

2013-07-04 Thread HighBeliever
I used the following code to import the functions of a dll in my Python code.

from ctypes import *

hunspell=CDLL('C:\Nhunspell\Hunspellx64.dll')
hunspell.HunspellInit.restype = POINTER(c_int)
hunspell.HunspellInit.argtypes = (c_char_p, c_char_p)
hunspell.HunspellSpell.argtypes = (POINTER(c_int), c_char_p)
hunspell.HunspellAdd.argtypes = (POINTER(c_int), c_char_p)
hunspell.HunspellSuggest.argtypes = (POINTER(c_int), 
POINTER(POINTER(c_char_p)), c_char_p)

class Hunspell(object):
def __init__(self):
self.hunhandle = hunspell.HunspellInit('en_US.aff', 
'en_US.dic')

a=Hunspell()

The class Hunspell should act as a wrapper for the function, but then I get 
this error when I try to run this.

Traceback (most recent call last):
  File C:\Users\KURO\Desktop\hunspell\text.py, line 49, in module
a=Hunspell()
  File C:\Users\KURO\Desktop\hunspell\text.py, line 17, in __init__
self.hunhandle = hunspell.HunspellInit('en_US.aff', 'en_US.dic')
WindowsError: exception: access violation reading 0x01FBB000

Please help me out.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2013-07-04 Thread feedthetroll
Am Mittwoch, 3. Juli 2013 19:00:50 UTC+2 schrieb rusi:
 On Wednesday, July 3, 2013 7:42:19 PM UTC+5:30, feedth...@gmx.de wrote:
  Any questions?
 YES! 
 Who is that hiding behind 'FeedTheTroll' ?

Oh, it's just yattt (yet another troll trolling troll) lurching around to find 
amazing threads (Well, in fact these threads stopped being amazing weeks ago. I 
must be some sort of masochist :-) )

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


Re: Important features for editors

2013-07-04 Thread Dave Angel

On 07/04/2013 03:59 AM, Νίκος wrote:

Στις 4/7/2013 10:32 πμ, ο/η cutems93 έγραψε:

I am researching on editors for my own reference. I found that each of
them has some features that other don't, but I am not sure which
features are significant/necessary for a GOOD editor. What features do
you a good editor should have? Keyboard shortcuts? Extensions?

Thanks!
Min


Download Sublime Text v3

Is a great editor



When possible, it's polite to supply a link to the page where it's 
described or can be downloaded.  In this case,


http://www.sublimetext.com/

It looks pretty good on the web page.  The main negatives I can see are:
It costs $70 per user
It can only be purchased with Paypal, which I won't use.
It's available for OS/X, Linux and Windows, with a single purchase
The eval/demo is not time-limited (currently)

The positives
It can be customized, apparently in Python
The simple customizations are specified by JSON files
Current download is version 2, but there's a version 3 beta, and if 
you buy now, you won't have an upgrade fee.


..

Note that the OP didn't ask which is a good editor, but which features 
make a good editor.  I'll post a response to that in a little while.



--
DaveA

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


UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος

I just started to have this error without changing nothing

in my index.html(template) and metrites.py(which ipen the template)

[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Original 
exception was:
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Traceback 
(most recent call last):
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97]   File 
/home/nikos/public_html/cgi-bin/metrites.py, line 19, in module
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] host = 
socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] 
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: 
invalid start byte
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature end 
of script headers: metrites.py



Why cant it decode the starting byte? what starting byte is that?
--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


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

2013-07-04 Thread feedthetroll
Am Mittwoch, 3. Juli 2013 19:01:23 UTC+2 schrieb ru...@yahoo.com:
 On 07/03/2013 08:12 AM, feedthetr...@gmx.de wrote:
 Am Mittwoch, 3. Juli 2013 12:00:14 UTC+2 schrieb Νίκος:
 Στις 3/7/2013 12:45 μμ, ο/η Chris Angelico έγραψε:
 ] You have betrayed the trust of all your customers.
 ...
 I just received a call form on of my customers asking me to explain your 
 mail ...
 Of course i should have give you the root pass(it was indeed stupid), 
 but you violated my trust.
 You should have been clear that you didnt want to help and not asking me 
 via private mail for the root pass.
 
 May i cite:
 Am Dienstag, 4. Juni 2013 19:12:41 UTC+2 schrieb Νικόλαος Κούρας:
 Τη Τρίτη, 4 Ιουνίου 2013 8:09:18 μ.μ. UTC+3, ο χρήστης Chris Angelico 
 έγραψε:
 On Wed, Jun 5, 2013 at 3:02 AM, Νικόλαος Κούρας nikos.gr...@gmail.com
 wrote:
 I'm willing to let someone with full root access to my webhost to see 
 thigns from the inside.
 ...
 You need to read up on what happens when you enter Dummy Mode and give
 someone full root access to your web host. You really REALLY need to
 understand what that means before you offer random strangers that kind
 of access to someone else's data.
 
 *
 *
 I've half a mind to take you up on your offer, then go look for
 personal and private info from your clients, and email it to them
 (along with a link to this thread) to point out what's going on.
 *
 *
 ChrisA
 
 I know what full root access mean.
 I also trust you.
 ...
  
 Am Mittwoch, 5. Juni 2013 00:12:26 UTC+2 schrieb Chris Angelico:
 The call is strong... I could rule the galaxy alongside my father...
 I've searched my feelings, and I know this to be true!
 
 *
 *
 Okay. I accept. I'll **do as I promised.** Might be interesting, and
 educative - for someone, at least.
 *
 *
 [emphasis added for those, who do not want to read the whole post]
 
 Any questions?
 
 Yes.  

Ahhh! Like you I *love* to answer rhetorical questions. ;-)

 If you tell someone you're going to beat them up but 
 they don't take you seriously because they are naive, 
 or they think you're kidding, or they don't understand 
 you because you told them in hints rather than directly, 
 is it ok to beat them up?

Yes, or the police would have to arrest every participant of a boxing, martial 
arts, ... championship.

 Are the existence of laws against beating people up
 negated because you told them in advance?  Or negated
 because they deserve the beating?

Yes, or every M.D. would be arrested. You allow him to cut your body and 
therefore it's O.K.

 Does it make any difference if they contribute to
 their own beating, say by showing up at a designated
 place and time?

Yes. In case of a punchfest (is this correct in english, the german word is 
Massenschlägerei) *every* participant is convicted.

 Does it make any difference if the beating is for 
 their own good?  (In the beater's opinion?)  (In
 the majority opinion?)

Yes. In case the one who confirms the their own good is an accredited 
specialist (psychiatrist, judge [yes there is corporal punishment in many, many 
legal systems, established and endorsed by majority opinion], ...)

 I am sorry Mr/Ms. FeedTheTroll for being so dumb.  

I forgive, no problem ;-)
And, if you have to be personal on a public list, I would prefer Mrs.

 I know the answers to all these questions are obvious 
 to everyone else here but I am not sure about them.

Then I hope, I was able to enlighten you. ;-)

btw: Highly offtopic. Therefore I'm out.

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


Re: Important features for editors

2013-07-04 Thread Dave Angel

On 07/04/2013 03:32 AM, cutems93 wrote:

I am researching on editors for my own reference. I found that each of them has 
some features that other don't, but I am not sure which features are 
significant/necessary for a GOOD editor. What features do you a good editor 
should have? Keyboard shortcuts? Extensions?



Not sure what you mean by keyboard shortcuts.  If you mean there should 
be a keyboard version of anything that can be done with the mouse, 
absolutely.


There are hundreds of features that could be listed, and only you can 
decide which ones are important.  I'll try to list a few that are 
important to me, and some more that would sure be nice.


Very important:
--

It runs on every platform I'm using.  It's extremely fast, when run 
locally, and reasonable over a slow internet connection.


Licensing is free, or very inexpensive

It opens and edits files of fairly arbitrary size (at least 10 MB)

It has a large number of potential buffers, for editing multiple files 
at the same time.


It can readily be customized, on a per-language basis, so that it can 
easily handle the quirks of each language.  And it switches between them 
based on file name, without explicitly setting some mode.  However, if 
the filename is unconventional, it allows the buffer to be explicitly 
set to a particular language, not affecting other files that are 
simultaneously open.


It comes pre-customized for the languages I'm likely to use now.  That 
includes pseudo languages like html, xml, css, not just programming 
languages.


It supports my own strange preferences for tab-handling, or at least can 
be customized to do so.


It recognizes immediately when a file has been changed on disk, and 
gives me reasonable ways to merge my current edits into what's now in 
the disk file.


It doesn't force me to accept .bak or other funny files;  that's what 
dvcs systems are for.  It CAN create such files while a file is being 
edited, they just shouldn't persist after the editor is normally closed.


If it has project files, they should be out of band, not mixed in with 
source files I'm editing.


Nice to have:


It has visible spaces (and tabs, and other funny white-space characters)

It can be run in an ssh session, remotely, over a satellite internet 
connection and vpn.


Customization language is one I'm comfortable with.  Not VBA or javascript.

Mandatory for Python use:


It understands indenting, and lets you easily get to the various columns 
that are legal at any point.  This means it recognizes if statements and 
suchlike, and indents (4) spaces for the following line.  And when you 
want to unindent, you don't have to use 4 backspaces, but just press the 
tab again.


Nice for Python use:
---

Syntax coloring.

Re-indenting a group of lines by plus-or-minus 4 columns.



Now, you may be asking about an IDE.  And that's a whole other kettle of 
fish.  Context-sensitive auto-completion, jump to definition, 
refactoring support, data breakpoints, ...



Candidates?
   emacs  - standard on most OS's, available for Windows from various 
websites

   Komodo Editfree
  http://www.activestate.com/komodo-edit
   Komodo IDE   not free
  http://www.activestate.com/komodo-ide


--
DaveA

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


Re: Important features for editors

2013-07-04 Thread Νίκος

Στις 4/7/2013 11:34 πμ, ο/η Dave Angel έγραψε:

On 07/04/2013 03:59 AM, Νίκος wrote:

Στις 4/7/2013 10:32 πμ, ο/η cutems93 έγραψε:

I am researching on editors for my own reference. I found that each of
them has some features that other don't, but I am not sure which
features are significant/necessary for a GOOD editor. What features do
you a good editor should have? Keyboard shortcuts? Extensions?

Thanks!
Min


Download Sublime Text v3

Is a great editor



When possible, it's polite to supply a link to the page where it's
described or can be downloaded.  In this case,

http://www.sublimetext.com/

It looks pretty good on the web page.  The main negatives I can see are:
 It costs $70 per user
 It can only be purchased with Paypal, which I won't use.
 It's available for OS/X, Linux and Windows, with a single purchase
 The eval/demo is not time-limited (currently)

The positives
 It can be customized, apparently in Python
 The simple customizations are specified by JSON files
 Current download is version 2, but there's a version 3 beta, and if
you buy now, you won't have an upgrade fee.

..

Note that the OP didn't ask which is a good editor, but which features
make a good editor.  I'll post a response to that in a little while.



If you guys want to use it i can send you a patch for it.
I know its illegal thing to say but it will help you use it without 
buying it.


--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Dave Angel

On 07/04/2013 04:37 AM, Νίκος wrote:

I just started to have this error without changing nothing

in my index.html(template) and metrites.py(which ipen the template)

[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Original
exception was: [Thu Jul 04 11:35:14 2013] [error] [client
108.162.229.97] Traceback (most recent call last): [Thu Jul 04
11:35:14 2013] [error] [client 108.162.229.97]   File
/home/nikos/public_html/cgi-bin/metrites.py, line 19, in module
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] host =
 socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
'UnResolved' [Thu Jul 04 11:35:14 2013] [error] [client
108.162.229.97] UnicodeDecodeError: 'utf-8' codec can't decode byte
0xb6 in position 0: invalid start byte [Thu Jul 04 11:35:14 2013]
[error] [client 108.162.229.97] Premature end of script headers:
metrites.py


Why cant it decode the starting byte? what starting byte is that?


The error message means that somebody is trying to decode a byte string
into Unicode, and using the utf-8 codec for it.  Only certain sequences
are legal in utf-8, and the first byte of a character may not be 0xb6.
So it gives an error.  The question is where does this string come from.


Well, the message shows the source line from metrites.py:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'

So the most likely candidate is the string in the environment named
REMOTE_ADDR  Can you display that string?  it should look like

11.24.32.4

or some other valid IP address.


I'm assuming Python 2.7.  You should specify the python version when 
starting a new thread, as we (or at least I) cannot keep track of what 
version everyone's running.





--
DaveA

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


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος

Στις 4/7/2013 12:59 μμ, ο/η Dave Angel έγραψε:

On 07/04/2013 04:37 AM, Νίκος wrote:

I just started to have this error without changing nothing

in my index.html(template) and metrites.py(which ipen the template)

[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Original
exception was: [Thu Jul 04 11:35:14 2013] [error] [client
108.162.229.97] Traceback (most recent call last): [Thu Jul 04
11:35:14 2013] [error] [client 108.162.229.97]   File
/home/nikos/public_html/cgi-bin/metrites.py, line 19, in module
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] host =
 socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
'UnResolved' [Thu Jul 04 11:35:14 2013] [error] [client
108.162.229.97] UnicodeDecodeError: 'utf-8' codec can't decode byte
0xb6 in position 0: invalid start byte [Thu Jul 04 11:35:14 2013]
[error] [client 108.162.229.97] Premature end of script headers:
metrites.py


Why cant it decode the starting byte? what starting byte is that?


The error message means that somebody is trying to decode a byte string
into Unicode, and using the utf-8 codec for it.  Only certain sequences
are legal in utf-8, and the first byte of a character may not be 0xb6.
So it gives an error.  The question is where does this string come from.


Well, the message shows the source line from metrites.py:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'

So the most likely candidate is the string in the environment named
REMOTE_ADDR  Can you display that string?  it should look like

11.24.32.4

or some other valid IP address.


I'm assuming Python 2.7.  You should specify the python version when
starting a new thread, as we (or at least I) cannot keep track of what
version everyone's running.


Ima using Python v3.3.2 Dave

The host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 
'UnResolved' should not have give an error since i explicityl tell it 
that if it cannot resolve dns the ip to hostname to set it as unresolved


The error appear ONLY when i CloudFlare superhost.gr

If i pause tthe domain form CloudFlare then my website loads properly.


--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Important features for editors

2013-07-04 Thread Chris Angelico
On Thu, Jul 4, 2013 at 7:14 PM, Νίκος ni...@superhost.gr wrote:
 If you guys want to use it i can send you a patch for it.
 I know its illegal thing to say but it will help you use it without buying
 it.

Considering that there are plenty of free text editors around, I don't
see any reason to steal one. If you want a pay-for editor, pay for it.
If you don't want to pay, use emacs or SciTE or nano or something.

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


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

2013-07-04 Thread Νίκος


Στις 3/7/2013 8:23 μμ, ο/η Chris Angelico έγραψε:

What are the file permissions (file modes) on all your home
directories? Do you know what they mean?



root@nikos [~]# ls -al /home
total 88
drwx--x--x 22 root root 4096 Jul  3 20:03 ./
drwxr-xr-x 22 root root 4096 Jun 12 01:21 ../
drwx--x--x 14 akis akis 4096 Apr  5 22:21 akis/
same with others just +x for group and others.

Does that mean you can easily i.e. 'cd /home/akis/' accessing their home
directories?


Yes.


You can cd to the other users home directories but you wont be able to
view their files because of the lack of +r attribute.

But i'll remove it just in case by:

chmod go-x -R /home/whatever_username


Yes they do, but cPanel offers some protection against these kind of

methods

called CPHulk so it wont be easy!


Neat. Now I know how to lock you out of your own account. Five seconds
with Google brought this up:

http://docs.cpanel.net/twiki/bin/view/11_30/WHMDocs/CPHulk

Can you, by reading that page, tell me what I would have to do to stop
you from accessing your login?


yes constantly ping my server by faking you ip address as my ip address
so to force CPHulk to refuse to let me login.

Of course the same page provides a means of how to unlock myself in case
that happens.


Also, CPHulk does not appear to have _any_ protection against
privilege escalation. It's a completely different thing.


Yes, it does not. Its mostly a way to block nmap requests of pinging and
identifying of services running on the server itself.

--
What is now proved was at first only imagined!


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


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Ulrich Eckhardt

Am 04.07.2013 10:37, schrieb Νίκος:

I just started to have this error without changing nothing


Well, undo the nothing that you didn't change. ;)


UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0:
invalid start byte
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature end
of script headers: metrites.py

Why cant it decode the starting byte? what starting byte is that?


It's the 0xb6 but it's expecting the starting byte of a UTF-8 sequence. 
Please do some research on UTF-8, that should clear it up. You could 
also search for common causes of that error.


Uli


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


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Dave Angel

On 07/04/2013 06:03 AM, Νίκος wrote:

Στις 4/7/2013 12:59 μμ, ο/η Dave Angel έγραψε:

On 07/04/2013 04:37 AM, Νίκος wrote:

I just started to have this error without changing nothing

in my index.html(template) and metrites.py(which ipen the template)

[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Original
exception was: [Thu Jul 04 11:35:14 2013] [error] [client
108.162.229.97] Traceback (most recent call last): [Thu Jul 04
11:35:14 2013] [error] [client 108.162.229.97]   File
/home/nikos/public_html/cgi-bin/metrites.py, line 19, in module
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] host =
 socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
'UnResolved' [Thu Jul 04 11:35:14 2013] [error] [client
108.162.229.97] UnicodeDecodeError: 'utf-8' codec can't decode byte
0xb6 in position 0: invalid start byte [Thu Jul 04 11:35:14 2013]
[error] [client 108.162.229.97] Premature end of script headers:
metrites.py


Why cant it decode the starting byte? what starting byte is that?


The error message means that somebody is trying to decode a byte string
into Unicode, and using the utf-8 codec for it.  Only certain sequences
are legal in utf-8, and the first byte of a character may not be 0xb6.
So it gives an error.  The question is where does this string come from.


Well, the message shows the source line from metrites.py:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
'UnResolved'

So the most likely candidate is the string in the environment named
REMOTE_ADDR  Can you display that string?  it should look like

11.24.32.4

or some other valid IP address.


I'm assuming Python 2.7.  You should specify the python version when
starting a new thread, as we (or at least I) cannot keep track of what
version everyone's running.


Ima using Python v3.3.2 Dave

The host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
'UnResolved' should not have give an error since i explicityl tell it
that if it cannot resolve dns the ip to hostname to set it as unresolved


That's not true.  The 'or' doesn't get executed until after the 
gethostbyaddr() call has returned.  So if something's wrong with that 
call, and it throws an exception, the 'or unresolved' won't help.


I don't know that this is the problem, and I'm not all familiar with 
these api's.  But I cannot see anything else that could go wrong there 
to give that particular exception.  Unless the hostname it's going to 
return is a byte string.




The error appear ONLY when i CloudFlare superhost.gr

If i pause tthe domain form CloudFlare then my website loads properly.




I don't really know what CloudFlare is, and have no idea what 'pausing 
the form' will do.  But since it has something to do with dns, perhaps 
it's returning an invalid host name, one that isn't encoded in utf-8.


--
DaveA

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


Fwd: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος




 Αρχικό μήνυμα 
Θέμα: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in 
position 0: invalid start byte

Ημερομηνία: Thu, 04 Jul 2013 06:29:25 -0400
Από: Dave Angel da...@davea.name
Προς: python-list@python.org
Ομάδες συζήτησης: comp.lang.python
Αναφορές: kr3c7k$tjs$2...@news.grnet.gr 
mailman.4214.1372931978.3114.python-l...@python.org 
kr3hab$jn0$1...@news.grnet.gr


On 07/04/2013 06:03 AM, Νίκος wrote:

Στις 4/7/2013 12:59 μμ, ο/η Dave Angel έγραψε:

On 07/04/2013 04:37 AM, Νίκος wrote:

I just started to have this error without changing nothing

in my index.html(template) and metrites.py(which ipen the template)

[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Original
exception was: [Thu Jul 04 11:35:14 2013] [error] [client
108.162.229.97] Traceback (most recent call last): [Thu Jul 04
11:35:14 2013] [error] [client 108.162.229.97]   File
/home/nikos/public_html/cgi-bin/metrites.py, line 19, in module
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] host =
 socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
'UnResolved' [Thu Jul 04 11:35:14 2013] [error] [client
108.162.229.97] UnicodeDecodeError: 'utf-8' codec can't decode byte
0xb6 in position 0: invalid start byte [Thu Jul 04 11:35:14 2013]
[error] [client 108.162.229.97] Premature end of script headers:
metrites.py


Why cant it decode the starting byte? what starting byte is that?


The error message means that somebody is trying to decode a byte string
into Unicode, and using the utf-8 codec for it.  Only certain sequences
are legal in utf-8, and the first byte of a character may not be 0xb6.
So it gives an error.  The question is where does this string come from.


Well, the message shows the source line from metrites.py:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
'UnResolved'

So the most likely candidate is the string in the environment named
REMOTE_ADDR  Can you display that string?  it should look like

11.24.32.4

or some other valid IP address.


I'm assuming Python 2.7.  You should specify the python version when
starting a new thread, as we (or at least I) cannot keep track of what
version everyone's running.


Ima using Python v3.3.2 Dave

The host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
'UnResolved' should not have give an error since i explicityl tell it
that if it cannot resolve dns the ip to hostname to set it as unresolved


That's not true.  The 'or' doesn't get executed until after the
gethostbyaddr() call has returned.  So if something's wrong with that
call, and it throws an exception, the 'or unresolved' won't help.

So how do you propose to write the above statement?
I was under the i impression then if for any reason the gethostbyaddr 
failed then or's argument will be returned instead.




The error appear ONLY when i CloudFlare superhost.gr

If i pause tthe domain form CloudFlare then my website loads properly.




I don't really know what CloudFlare is, and have no idea what 'pausing
the form' will do.  But since it has something to do with dns, perhaps
it's returning an invalid host name, one that isn't encoded in utf-8.

I think so too.

--
What is now proved was at first only imagined!


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


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος

Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:

Am 04.07.2013 10:37, schrieb Νίκος:

I just started to have this error without changing nothing


Well, undo the nothing that you didn't change. ;)


UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0:
invalid start byte
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature end
of script headers: metrites.py

Why cant it decode the starting byte? what starting byte is that?


It's the 0xb6 but it's expecting the starting byte of a UTF-8 sequence.
Please do some research on UTF-8, that should clear it up. You could
also search for common causes of that error.


So you are also suggesting that what gesthostbyaddr() returns is not 
utf-8 encoded too?


What character is 0xb6 anyways?

--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Chris Angelico
On Thu, Jul 4, 2013 at 8:38 PM, Νίκος ni...@superhost.gr wrote:
 So you are also suggesting that what gesthostbyaddr() returns is not utf-8
 encoded too?

 What character is 0xb6 anyways?

It isn't. It's a byte. Bytes are not characters.

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

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


Re: Important features for editors

2013-07-04 Thread Robert Kern

On 2013-07-04 10:14, Νίκος wrote:


If you guys want to use it i can send you a patch for it.
I know its illegal thing to say but it will help you use it without buying it.


Please do not use this forum to make such offers.

--
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


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread MRAB

On 04/07/2013 11:38, Νίκος wrote:

Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:

Am 04.07.2013 10:37, schrieb Νίκος:

I just started to have this error without changing nothing


Well, undo the nothing that you didn't change. ;)


UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0:
invalid start byte
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature end
of script headers: metrites.py

Why cant it decode the starting byte? what starting byte is that?


It's the 0xb6 but it's expecting the starting byte of a UTF-8 sequence.
Please do some research on UTF-8, that should clear it up. You could
also search for common causes of that error.


So you are also suggesting that what gesthostbyaddr() returns is not
utf-8 encoded too?

What character is 0xb6 anyways?


Well, it's from a bytestring, so you'll have to specify what encoding
you're using! (It clearly isn't UTF-8.)

If it's ISO-8859-7 (what you've previously referred to as greek-iso),
then:

 import unicodedata
 unicodedata.name(b\xb6.decode(ISO-8859-7))
'GREEK CAPITAL LETTER ALPHA WITH TONOS'

You'll need to find out where that bytestring is coming from.

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


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

2013-07-04 Thread Antoon Pardon
Op 04-07-13 01:40, Joshua Landau schreef:

 On 3 July 2013 11:01, Antoon Pardon antoon.par...@rece.vub.ac.be wrote:

 This is not an attack of character. Level of skill/competence is
 not in general seen as a character trait.
 I disagree. I'm not sure how to argue this, rather than point out that
 by character trait I'm not talking about intrinsic trait but
 rather revolving around who you are. The alternative I posed is
 talking about things revolving around specific actions that you have
 taken.

All right I can work with that. However I get the impression what you
are talking about is then not limited to character traits but can be
applied to other traits too. It is unlikely to come up in this group
but I guess you would be opposed in a similar way to someone being
called a weakling after it became clear he was not physically fit for
a particular task.


 But how do I describe this in one word? What conclusion am I allowed
 to make from all this?
 That it's worth taking a little more time doing things if it makes
 sure you aren't harming the person on the other end.

I agree to a certain extend. But sometimes I seem to come up (not only
on usenet but in real life too) to people who seem to be oblivious to
the message you are sending until you cast it into words that sting.

I have been guily of such behaviour myself, not really reacting to the
warnings from my partner until they were termed in a way that was hard
to ignore.

And sure, there is a serious risk of a hostile reaction, but getting
a hostile reaction doesn't contradict that it was effective. People
often do change their behaviour even if there first reaction was hostile
and denial.

So I'll agree to doing as little harm as possible and that there is
a level of harm that shouldn't be crossed. But I won't go as far as
making sure no harm is done.



 [examples]
 Bear in mind that if the way you were acting was all in my with
 trepidation category, I would likely have not spoken up. I believe
 you crossed a lot further beyond that line.

I had to look up trepidation and the translation I got from my
dictionary was not 100% helpful. Would hesitation or wariness
be a good substitute.

Can we go back to my first entry in this thread? I would like to
know whether you think that already crossed the line or if that
would fall under your with trepidation category and I crossed
the line later.

I think the relevant part is this:

] Maybe that way he'll learn that if he doesn't want to be considered
] an incompetent inconsiderate jerk, he shouldn't behave like one.

-- 
Antoon Pardon 

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


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος

Στις 4/7/2013 1:54 μμ, ο/η Chris Angelico έγραψε:

On Thu, Jul 4, 2013 at 8:38 PM, � ni...@superhost.gr wrote:

So you are also suggesting that what gesthostbyaddr() returns is not utf-8
encoded too?

What character is 0xb6 anyways?


It isn't. It's a byte. Bytes are not characters.

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


Well in case of utf-8 encoding for the first 127 codepoing we can safely 
say that a character equals a byte :)


--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος

Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε:

On 04/07/2013 11:38, Νίκος wrote:

Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:

Am 04.07.2013 10:37, schrieb Νίκος:

I just started to have this error without changing nothing


Well, undo the nothing that you didn't change. ;)


UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0:
invalid start byte
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature
end
of script headers: metrites.py

Why cant it decode the starting byte? what starting byte is that?


It's the 0xb6 but it's expecting the starting byte of a UTF-8 sequence.
Please do some research on UTF-8, that should clear it up. You could
also search for common causes of that error.


So you are also suggesting that what gesthostbyaddr() returns is not
utf-8 encoded too?

What character is 0xb6 anyways?


Well, it's from a bytestring, so you'll have to specify what encoding
you're using! (It clearly isn't UTF-8.)

If it's ISO-8859-7 (what you've previously referred to as greek-iso),
then:

  import unicodedata
  unicodedata.name(b\xb6.decode(ISO-8859-7))
'GREEK CAPITAL LETTER ALPHA WITH TONOS'

You'll need to find out where that bytestring is coming from.


Right.
But nowhere in my script(metrites.py) i use an 'Ά' so i really have no 
clue where this is coming from.


And you are right if it was a byte came from an utf-8 encoding scheme 
then it would be automatically decoded.


The only thing i can say for use is that this problem a[[ear only when i 
cloudflare my domain superhost.gr


If i un-cloudlflare it it cease to display errors.

Can you tell me hpw to write the following properly:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'

so even if the function fails unresolved to be returned back?
Somehow i need to capture the error.

Or it dosnt have to do it the or operand will be returned?



--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread MRAB

On 04/07/2013 12:29, Νίκος wrote:

Στις 4/7/2013 1:54 μμ, ο/η Chris Angelico έγραψε:

On Thu, Jul 4, 2013 at 8:38 PM, � ni...@superhost.gr wrote:

So you are also suggesting that what gesthostbyaddr() returns is not utf-8
encoded too?

What character is 0xb6 anyways?


It isn't. It's a byte. Bytes are not characters.

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


Well in case of utf-8 encoding for the first 127 codepoing we can safely
say that a character equals a byte :)


Equals? No. Bytes are not characters. (Strictly speaking, they're
codepoints, not characters.)

And anyway, it's the first _128_ codepoints.
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread MRAB

On 04/07/2013 12:36, Νίκος wrote:

Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε:

On 04/07/2013 11:38, Νίκος wrote:

Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:

Am 04.07.2013 10:37, schrieb Νίκος:

I just started to have this error without changing nothing


Well, undo the nothing that you didn't change. ;)


UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0:
invalid start byte
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature
end
of script headers: metrites.py

Why cant it decode the starting byte? what starting byte is that?


It's the 0xb6 but it's expecting the starting byte of a UTF-8 sequence.
Please do some research on UTF-8, that should clear it up. You could
also search for common causes of that error.


So you are also suggesting that what gesthostbyaddr() returns is not
utf-8 encoded too?

What character is 0xb6 anyways?


Well, it's from a bytestring, so you'll have to specify what encoding
you're using! (It clearly isn't UTF-8.)

If it's ISO-8859-7 (what you've previously referred to as greek-iso),
then:

  import unicodedata
  unicodedata.name(b\xb6.decode(ISO-8859-7))
'GREEK CAPITAL LETTER ALPHA WITH TONOS'

You'll need to find out where that bytestring is coming from.


Right.
But nowhere in my script(metrites.py) i use an 'Ά' so i really have no
clue where this is coming from.

And you are right if it was a byte came from an utf-8 encoding scheme
then it would be automatically decoded.

The only thing i can say for use is that this problem a[[ear only when i
cloudflare my domain superhost.gr

If i un-cloudlflare it it cease to display errors.

Can you tell me hpw to write the following properly:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 'UnResolved'

so even if the function fails unresolved to be returned back?
Somehow i need to capture the error.

Or it dosnt have to do it the or operand will be returned?


If gethostbyaddr fails, it raises socket.gaierror, (which, from Python
3.3 onwards, is a subclass of OSError), so try catching that, setting
'host' to 'UnResolved' if it's raised.

Also, try printing out ascii(os.environ['REMOTE_ADDR']).

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


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

2013-07-04 Thread Antoon Pardon
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.

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.


  And yes, I think wouldn't antagonize your
 boss is not a bad heuristic for judging the politeness of 
 your response.

That may be true for you personnally, but you are unsufficiently
clear for anyone else to be of any help. The problem is that
when you wrote this, you had a specific kind of boss in mind
who would react in certain ways to certain kinds of treatment.
However it would be extremely unlikely that other people
would come up with the same idea of boss. And not everybody
is in the same situation, some people can't afford to lose
there job, others are in a less desperate situation, for
some people their priority is their career, while for others
it is the service to their clients. All these people are going
to come up with wildly different answers.


 Again I ask, what does his web site admin skills or lack
 thereof have to do with python?

 If you want to decline providing Python help to someone 
 because you don't like some real-world behavior of the 
 person, fine.  But when you attack him over it, and 
 publicly engage in a long, noisy discussion here in 
 which you trumpet your moral and technical superiority,
 then you should not be surprised when the target takes 
 offense and responds in kind.

 If someone from Wikileaks posts here seeking Python help, 
 should we engage in a long discussion about the morality 
 of Wikileaks and how they aid US fugitives from justice?

 How about someone who lets slip he's just been released 
 from prison for child sexual abuse? 

 How about someone who's writing software for bulk mailing?

 How about someone who is writing membership management 
 software for the American Nazi Party?

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?



 Please use non-emotional, neutral, factual descriptions
 and only do so when it is actually relevant.  IOW, please 
 resist your desire to tell off the poster -- it usually
 just produces more responses in kind.
 This is often not workable. Limiting to factual description
 means that you often can't summarize a list of such factual
 descriptions into a conclusion. You can list 8 examples of
 someone betraying the trust of his customers but you can't
 summarize it into: is/behaves untrustworthy to his customers,
 even if all signs point to this person going to continue in the
 same vein.

 It is limiting yourself into pointing out all the trees
 without being allowed to call it a forest.
 You can summarize while being polite and non-judgmental.

Somethings are not expressable in a way that is acceptable
to who you are talking too, simply because they find the
fact or opinion to be hurtful/insulting in itself.


 You do not have state your belief on every off-topic 
 inflammatory subject that happens to come up.

So what do you suggest? That we simply let those who
bring up an off-topic inflammatory subject, go on
about it whithout challenge?

-- 
Antoon Pardon



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


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος

Στις 4/7/2013 2:52 μμ, ο/η MRAB έγραψε:

On 04/07/2013 12:29, Νίκος wrote:

Στις 4/7/2013 1:54 μμ, ο/η Chris Angelico έγραψε:

On Thu, Jul 4, 2013 at 8:38 PM, � ni...@superhost.gr wrote:

So you are also suggesting that what gesthostbyaddr() returns is not
utf-8
encoded too?

What character is 0xb6 anyways?


It isn't. It's a byte. Bytes are not characters.

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


Well in case of utf-8 encoding for the first 127 codepoing we can safely
say that a character equals a byte :)


Equals? No. Bytes are not characters. (Strictly speaking, they're
codepoints, not characters.)

And anyway, it's the first _128_ codepoints.


Yes 0-127 = 128, i knew that!

Well the relationship between characters and bytes is that:

A [0-127] Unicode codepoints(characters) need 1-byte to be stored in 
utf-8 encoding.


I think its also correct to say that the byte in the above situation is 
the representation of our character.


--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Chris Angelico
On Thu, Jul 4, 2013 at 9:52 PM, MRAB pyt...@mrabarnett.plus.com wrote:
 On 04/07/2013 12:29, Νίκος wrote:

 Στις 4/7/2013 1:54 μμ, ο/η Chris Angelico έγραψε:

 On Thu, Jul 4, 2013 at 8:38 PM, � ni...@superhost.gr wrote:

 So you are also suggesting that what gesthostbyaddr() returns is not
 utf-8
 encoded too?

 What character is 0xb6 anyways?


 It isn't. It's a byte. Bytes are not characters.

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


 Well in case of utf-8 encoding for the first 127 codepoing we can safely
 say that a character equals a byte :)

 Equals? No. Bytes are not characters. (Strictly speaking, they're
 codepoints, not characters.)

 And anyway, it's the first _128_ codepoints.

As MRAB says, even if there's a 1:1 correspondence between bytes,
codepoints, and characters, they're still not the same thing. Plus,
0xb6 is not in the first 128, so your statement is false and your
question has no answer. Do you understand why I gave you that link? If
not, go read the page linked to.

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


Re: Default scope of variables

2013-07-04 Thread Lele Gaifax
Dave Angel da...@davea.name writes:

 Well, the number wouldn't be 63,000,000.  Rather it'd be 63**100

Uhm, if we are talking about Py2, then you should not count all the
combinations starting with a digit, while under Py3 the number explodes,
as this is valid code:

 à = 1
 à
1

:-)

back to easily-enumerable issues,
ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


Re: Coping with cyclic imports

2013-07-04 Thread kanchan . n . mahajan
On Tuesday, April 8, 2008 10:06:46 PM UTC+2, Torsten Bronger wrote:
 Hallöchen!
 
 I have a rather fat module that represents a document parser --
 inline elements, block elements, and the like.  Now I want to split
 it into many modules to make everything more manageable.
 
 But at the moment I don't see how to avoid cyclic imports:  A
 document element A, which is represented my module parser.A, may
 contain the element B, as defined in parser.B.  And vice versa.  So
 both modules must import each other, as far as I can see.
 
 I know that cyclic imports work in Python under certain
 circumstances.  Can anyone refer me to a page which explains *when*
 this works?  Because at least once, the imported module was not
 finished and thus largely unusual.
 
 Thank you!
 
 Tschö,
 Torsten.
 


If you do import foo inside bar and import bar inside foo, it will work 
fine. By the time anything actually runs, both modules will be fully loaded and 
will have references to each other.

The problem is when instead you do from foo import abc and from bar import 
xyz. Because now each module requires the other module to already be compiled 
(so that the name we are importing exists) before it can be compiled.

from
http://stackoverflow.com/questions/744373/circular-or-cyclic-imports-in-python
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος

Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:

On 04/07/2013 12:36, Νίκος wrote:

Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε:

On 04/07/2013 11:38, Νίκος wrote:

Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:

Am 04.07.2013 10:37, schrieb Νίκος:

I just started to have this error without changing nothing


Well, undo the nothing that you didn't change. ;)


UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in
position 0:
invalid start byte
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature
end
of script headers: metrites.py

Why cant it decode the starting byte? what starting byte is that?


It's the 0xb6 but it's expecting the starting byte of a UTF-8
sequence.
Please do some research on UTF-8, that should clear it up. You could
also search for common causes of that error.


So you are also suggesting that what gesthostbyaddr() returns is not
utf-8 encoded too?

What character is 0xb6 anyways?


Well, it's from a bytestring, so you'll have to specify what encoding
you're using! (It clearly isn't UTF-8.)

If it's ISO-8859-7 (what you've previously referred to as greek-iso),
then:

  import unicodedata
  unicodedata.name(b\xb6.decode(ISO-8859-7))
'GREEK CAPITAL LETTER ALPHA WITH TONOS'

You'll need to find out where that bytestring is coming from.


Right.
But nowhere in my script(metrites.py) i use an 'Ά' so i really have no
clue where this is coming from.

And you are right if it was a byte came from an utf-8 encoding scheme
then it would be automatically decoded.

The only thing i can say for use is that this problem a[[ear only when i
cloudflare my domain superhost.gr

If i un-cloudlflare it it cease to display errors.

Can you tell me hpw to write the following properly:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
'UnResolved'

so even if the function fails unresolved to be returned back?
Somehow i need to capture the error.

Or it dosnt have to do it the or operand will be returned?


If gethostbyaddr fails, it raises socket.gaierror, (which, from Python
3.3 onwards, is a subclass of OSError), so try catching that, setting
'host' to 'UnResolved' if it's raised.

Also, try printing out ascii(os.environ['REMOTE_ADDR']).



I have followed your suggestion by trying this:

try:
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except socket.gaierror:
host = UnResolved

and then re-cloudlflared superhost.gr domain

http://superhost.gr/ gives internal server error.

--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος

Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:

Also, try printing out ascii(os.environ['REMOTE_ADDR']).


'108.162.229.97' is the result of:

print( ascii(os.environ['REMOTE_ADDR']) )

Seems perfectly valid. and also have a PTR record, so that leaved us 
clueless about the internal server error.

--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Google earth

2013-07-04 Thread dave poreh
Folks, 
Hi, 
I am an IDL users and i have started to check out some pythons abilities, and 
turns out it is really cool. I just wondering if there is a Google earth module 
that we could import out lat-lon-(data) based on python codes. I have this web 
site (https://code.google.com/p/kdm-idl/) that i usually take my KML files to. 
Is there any work similar this happened in python before?

Thanks for any help in advance, 
Cheers,
Dave
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Ulrich Eckhardt

Am 04.07.2013 12:38, schrieb Νίκος:

Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:

Am 04.07.2013 10:37, schrieb Νίκος:

Why cant it decode the starting byte? what starting byte is that?


It's the 0xb6 but it's expecting the starting byte of a UTF-8 sequence.
Please do some research on UTF-8, that should clear it up. You could
also search for common causes of that error.


So you are also suggesting that what gesthostbyaddr() returns is not
utf-8 encoded too?


I never said that. And do some research yourself, you were given plenty 
of hints.


Uli

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


Re: Important features for editors

2013-07-04 Thread Tim Chase
On 2013-07-04 05:02, Dave Angel wrote:
[snip an excellent list of things to look for in an editor]

Also, 

- the ability to perform changes in bulk, especially across files.
  Often, this is done with the ability to record/playback macros,
  though some editors have multiple insertion/edit cursors; others
  allow for performing a bulk-change command across the entire file
  or list of files.

- folding (the ability to collapse multiple lines of text down to one
  line).  Especially if there are various ways to do it (manual
  folding, language-block folding, folding by indentation)

- multiple clipboard buffers/registers

- multiple bookmarks

- the ability to interact with external programs (piping a portion of
  a file through an external utility)

- a good community around it in case you have questions

- easy navigation to important things in your file (where
  important may vary based on file-type, but may include function
  definitions, paragraph boundaries, matching
  paren/bracket/brace/tag, etc)

Other nice-to-haves include

- split window editing
- tabbed windows
- Unicode support (including various encodings)
- vimgolf.com ;-)

 Candidates?
 emacs  - standard on most OS's, available for Windows from

And I'll put in a plug for Vim.

-tkc







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


Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?

2013-07-04 Thread Aseem Bansal
I want to start GUI development using Tkinter in Python 2.7.5.

I have been searching all over google but couldn't find any IDE that has 
drag-and-drop feature for Python GUI development. Tried to ask on stackoverflow 

(http://stackoverflow.com/questions/17439620/an-ide-with-drag-and-drop-feature-for-python-2-7-tkinter)

but couldn't get an answer there. So is there any IDE that can be used for GUI 
developemnt and has drag-and-drop feature for Python GUI dev?

I came across somewhere that eclipse's pydev plugin can be used but couldn't 
find anything on its website.

Any advice about this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος Γκρ33κ

Στις 4/7/2013 4:07 μμ, ο/η Ulrich Eckhardt έγραψε:

Am 04.07.2013 12:38, schrieb Νίκος:

Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:

Am 04.07.2013 10:37, schrieb Νίκος:

Why cant it decode the starting byte? what starting byte is that?


It's the 0xb6 but it's expecting the starting byte of a UTF-8 sequence.
Please do some research on UTF-8, that should clear it up. You could
also search for common causes of that error.


So you are also suggesting that what gesthostbyaddr() returns is not
utf-8 encoded too?


I never said that. And do some research yourself, you were given plenty
of hints.

Uli

Yes and as you can see form my responses i have tried any suggestion so 
far and the problem still remains unresolved.


What you said implied that the string returned by the function cannot be 
decoded as utf-8.


--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Important features for editors

2013-07-04 Thread Steve Simmons
Νίκος ni...@superhost.gr wrote:

Στις 4/7/2013 11:34 πμ, ο/η Dave Angel έγραψε:
 On 07/04/2013 03:59 AM, Νίκος wrote:
 Στις 4/7/2013 10:32 πμ, ο/η cutems93 έγραψε:
 I am researching on editors for my own reference. I found that each
of
 them has some features that other don't, but I am not sure which
 features are significant/necessary for a GOOD editor. What features
do
 you a good editor should have? Keyboard shortcuts? Extensions?

 Thanks!
 Min

 Download Sublime Text v3

 Is a great editor


 When possible, it's polite to supply a link to the page where it's
 described or can be downloaded.  In this case,

 http://www.sublimetext.com/

 It looks pretty good on the web page.  The main negatives I can see
are:
  It costs $70 per user
  It can only be purchased with Paypal, which I won't use.
  It's available for OS/X, Linux and Windows, with a single
purchase
  The eval/demo is not time-limited (currently)

 The positives
  It can be customized, apparently in Python
  The simple customizations are specified by JSON files
  Current download is version 2, but there's a version 3 beta, and
if
 you buy now, you won't have an upgrade fee.

 ..

 Note that the OP didn't ask which is a good editor, but which
features
 make a good editor.  I'll post a response to that in a little while.


If you guys want to use it i can send you a patch for it.
I know its illegal thing to say but it will help you use it without 
buying it.

-- 
What is now proved was at first only imagined!
-- 
http://mail.python.org/mailman/listinfo/python-list

Boy oh boy! You really are a slow learner Nicos. You have just offered to 
commit a crime and to include dozens of others in that crime ON A PUBLIC FORUM. 
Please think before you post. 

Sent from a Galaxy far far away-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread MRAB

On 04/07/2013 13:52, Νίκος wrote:

Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:

Also, try printing out ascii(os.environ['REMOTE_ADDR']).


'108.162.229.97' is the result of:

print( ascii(os.environ['REMOTE_ADDR']) )

Seems perfectly valid. and also have a PTR record, so that leaved us
clueless about the internal server error.


For me, socket.gethostbyaddr('108.162.229.97') raises socket.herror,
which is also a subclass of OSError from Python 3.3 onwards.

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


Re: Coping with cyclic imports

2013-07-04 Thread Dave Angel

On 07/04/2013 08:48 AM, kanchan.n.maha...@gmail.com wrote:

On Tuesday, April 8, 2008 10:06:46 PM UTC+2, Torsten Bronger wrote:

Hallöchen!

I have a rather fat module that represents a document parser --
inline elements, block elements, and the like.  Now I want to split
it into many modules to make everything more manageable.

But at the moment I don't see how to avoid cyclic imports:  A
document element A, which is represented my module parser.A, may
contain the element B, as defined in parser.B.  And vice versa.  So
both modules must import each other, as far as I can see.

I know that cyclic imports work in Python under certain
circumstances.  Can anyone refer me to a page which explains *when*
this works?  Because at least once, the imported module was not
finished and thus largely unusual.

Thank you!

Tschö,
Torsten.




If you do import foo inside bar and import bar inside foo, it will work 
fine. By the time anything actually runs, both modules will be fully loaded and will have 
references to each other.

The problem is when instead you do from foo import abc and from bar import 
xyz. Because now each module requires the other module to already be compiled (so that the 
name we are importing exists) before it can be compiled.

from
http://stackoverflow.com/questions/744373/circular-or-cyclic-imports-in-python



That's a nice looking oversimplification.  But it's not true if 
top-level code in the second module to be imported tries to use symbols 
defined in the first module.  And it's definitely bad practice, with 
weird bugs if either one of these files is the main script being loaded.



--
DaveA

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


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread MRAB

On 04/07/2013 13:47, Νίκος wrote:

Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:

On 04/07/2013 12:36, Νίκος wrote:

Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε:

On 04/07/2013 11:38, Νίκος wrote:

Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:

Am 04.07.2013 10:37, schrieb Νίκος:

I just started to have this error without changing nothing


Well, undo the nothing that you didn't change. ;)


UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in
position 0:
invalid start byte
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Premature
end
of script headers: metrites.py

Why cant it decode the starting byte? what starting byte is that?


It's the 0xb6 but it's expecting the starting byte of a UTF-8
sequence.
Please do some research on UTF-8, that should clear it up. You could
also search for common causes of that error.


So you are also suggesting that what gesthostbyaddr() returns is not
utf-8 encoded too?

What character is 0xb6 anyways?


Well, it's from a bytestring, so you'll have to specify what encoding
you're using! (It clearly isn't UTF-8.)

If it's ISO-8859-7 (what you've previously referred to as greek-iso),
then:

  import unicodedata
  unicodedata.name(b\xb6.decode(ISO-8859-7))
'GREEK CAPITAL LETTER ALPHA WITH TONOS'

You'll need to find out where that bytestring is coming from.


Right.
But nowhere in my script(metrites.py) i use an 'Ά' so i really have no
clue where this is coming from.

And you are right if it was a byte came from an utf-8 encoding scheme
then it would be automatically decoded.

The only thing i can say for use is that this problem a[[ear only when i
cloudflare my domain superhost.gr

If i un-cloudlflare it it cease to display errors.

Can you tell me hpw to write the following properly:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
'UnResolved'

so even if the function fails unresolved to be returned back?
Somehow i need to capture the error.

Or it dosnt have to do it the or operand will be returned?


If gethostbyaddr fails, it raises socket.gaierror, (which, from Python
3.3 onwards, is a subclass of OSError), so try catching that, setting
'host' to 'UnResolved' if it's raised.

Also, try printing out ascii(os.environ['REMOTE_ADDR']).



I have followed your suggestion by trying this:

try:
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except socket.gaierror:
host = UnResolved

and then re-cloudlflared superhost.gr domain

http://superhost.gr/ gives internal server error.


Try catching OSError instead. (As I said, from Python 3.3,
socket.gaierror is a subclass of it.)

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


Re: Important features for editors

2013-07-04 Thread Νίκος Γκρ33κ

Στις 4/7/2013 4:33 μμ, ο/η Steve Simmons έγραψε:

Νίκος ni...@superhost.gr wrote:

Στις 4/7/2013 11:34 πμ, ο/η Dave Angel έγραψε:

On 07/04/2013 03:59 AM, Νίκος wrote:

Στις 4/7/2013 10:32 πμ, ο/η cutems93 έγραψε:

I am researching on editors for my own reference. I
found that each of
them has some features that other don't, but I am not
sure which
features are significant/necessary for a GOOD editor.
What features do
you a good editor should have? Keyboard shortcuts?
Extensions?

Thanks!
Min


Download Sublime Text v3

Is a great editor



When possible, it's polite to supply a link to the page where it's
described or can be downloaded. In this case,

http://www.sublimetext.com/

It looks pretty good on the web page. The main negatives I can
see are:
It costs $70 per user
It can only be purchased with Paypal, which I won't use.
It's available for OS/X, Linux and Windows, with a single purchase
The eval/demo is not time-limited (currently)

The positives
It can be customized, apparently in Python
The simple customizations are specified by JSON files
Current download is version 2, but there's a version 3 beta, and if
you buy now, you won't have an upgrade fee.

..

Note that the OP didn't ask which is a good editor, but which
features
make a good editor. I'll post a response to that in a little while.



If you
guys want to use it i can send you a patch for it.
I know its illegal thing to say but it will help you use it without
buying it.


Boy oh boy! You really are a slow learner Nicos. You have just offered
to commit a crime and to include dozens of others in that crime ON A
PUBLIC FORUM. Please think before you post.

Sent from a Galaxy far far away


Just wanted to help people that might wanted it, thats all, its a great 
editor, but i wont post in public again such propositions.


--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Important features for editors

2013-07-04 Thread feedthetroll
Am Donnerstag, 4. Juli 2013 15:36:02 UTC+2 schrieb Νίκος Γκρ33κ:
 Στις 4/7/2013 4:33 μμ, ο/η Steve Simmons έγραψε:
 Νίκος ni...@superhost.gr wrote:
 Στις 4/7/2013 11:34 πμ, ο/η Dave Angel έγραψε:
 On 07/04/2013 03:59 AM, Νίκος wrote:
 ...
 Download Sublime Text v3
 Is a great editor
 ...
It looks pretty good on the web page. The main negatives I can
see are:
It costs $70 per user
It can only be purchased with Paypal, which I won't use.
 ...
 If you
 guys want to use it i can send you a patch for it.
 I know its illegal thing to say but it will help you use it without
 buying it.

 Boy oh boy! You really are a slow learner Nicos. You have just offered
 to commit a crime and to include dozens of others in that crime ON A
 PUBLIC FORUM. Please think before you post.
 ...
 Just wanted to help people that might wanted it, thats all, its a great 
 editor, but i wont post in public again such propositions.

Ahh, I see. Committing crimes is O.K. as long as
1. I think I help other with it and
2. I do not talk about it.

Yep. That's a great attitude towards life.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Important features for editors

2013-07-04 Thread rusi
On Thursday, July 4, 2013 7:03:19 PM UTC+5:30, Steve Simmons wrote:
 Boy oh boy! You really are a slow learner Nicos. You have just offered to 
 commit a crime and to include dozens of others in that crime ON A PUBLIC 
 FORUM. Please think before you post. 

For the record Steve, let me say, I find Robert Kern's objection barely 
sufficient.

And yours less than that.

Note that you are not objecting to the crime but to the public expression of it.
Just look at your objection from the angle of a police officer, and you will 
see that it can certainly be construed as abetment/collusion (or whatever is 
the legalistic jargon. Obviously IANAL)

For the sake of covering my own arse let me say:
1. I have earlier described Nikos as a petty-criminal and consider myself 
justified.
2. I have earlier described condoning him as collusion and I reiterate that 
claim.

And I add
3. The collective actions of this list will help determine further whether he 
climbs or descends the criminal ladder.

Beyond that I reiterate what I said earlier in this thread: These discussions  
'in-band' are counter-productive.

Setting up something like an invite-only yahoo or google group or some such to 
discuss this is free and takes 5 minutes.

I would have offered to do it but some people like Joshua Landau seem to think 
I am interested in world (aka Python-list) domination so not offering.
I was actually going to suggest that Steven d'Aprano do it. However before I 
could do that, he said (in CoC thread) that policing is not possible. Saddens 
me...

So I am suggesting you do it.

If I am invited I will contribute my 2c. If not, no objection: I dont consider 
myself a very important member of this list.

And yes: I hope you will consider rewording your objection, if not anything to 
cover your own you-know-what-where!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: DOS or not? [was Re: How to tell Script to use pythonw.exe ?]

2013-07-04 Thread Wayne Werner

On Wed, 3 Jul 2013, Dennis Lee Bieber wrote:


Consider that the Powershell default is to /prevent/ execution of
script files unless some security settings have been changed; even local
script files need to be signed to be executed.


Protip: No they don't - wrap it in a cmd/bat file and have it launch 
powershell[1]:


powershell -ExecutionPolicy Bypass -File ...


\o/

Microsoft security at it again! (reminds me a bit of just pushing 
Cancel to log into windows 98, I think it was)


-W

[1]: http://stackoverflow.com/q/728143/344286
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος Γκρ33κ

Στις 4/7/2013 4:34 μμ, ο/η MRAB έγραψε:

On 04/07/2013 13:47, Νίκος wrote:

Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:

On 04/07/2013 12:36, Νίκος wrote:

Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε:

On 04/07/2013 11:38, Νίκος wrote:

Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:

Am 04.07.2013 10:37, schrieb Νίκος:

I just started to have this error without changing nothing


Well, undo the nothing that you didn't change. ;)


UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in
position 0:
invalid start byte
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97]
Premature
end
of script headers: metrites.py

Why cant it decode the starting byte? what starting byte is that?


It's the 0xb6 but it's expecting the starting byte of a UTF-8
sequence.
Please do some research on UTF-8, that should clear it up. You could
also search for common causes of that error.


So you are also suggesting that what gesthostbyaddr() returns is not
utf-8 encoded too?

What character is 0xb6 anyways?


Well, it's from a bytestring, so you'll have to specify what encoding
you're using! (It clearly isn't UTF-8.)

If it's ISO-8859-7 (what you've previously referred to as
greek-iso),
then:

  import unicodedata
  unicodedata.name(b\xb6.decode(ISO-8859-7))
'GREEK CAPITAL LETTER ALPHA WITH TONOS'

You'll need to find out where that bytestring is coming from.


Right.
But nowhere in my script(metrites.py) i use an 'Ά' so i really have no
clue where this is coming from.

And you are right if it was a byte came from an utf-8 encoding scheme
then it would be automatically decoded.

The only thing i can say for use is that this problem a[[ear only
when i
cloudflare my domain superhost.gr

If i un-cloudlflare it it cease to display errors.

Can you tell me hpw to write the following properly:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
'UnResolved'

so even if the function fails unresolved to be returned back?
Somehow i need to capture the error.

Or it dosnt have to do it the or operand will be returned?


If gethostbyaddr fails, it raises socket.gaierror, (which, from Python
3.3 onwards, is a subclass of OSError), so try catching that, setting
'host' to 'UnResolved' if it's raised.

Also, try printing out ascii(os.environ['REMOTE_ADDR']).



I have followed your suggestion by trying this:

try:
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except socket.gaierror:
host = UnResolved

and then re-cloudlflared superhost.gr domain

http://superhost.gr/ gives internal server error.


Try catching OSError instead. (As I said, from Python 3.3,
socket.gaierror is a subclass of it.)



At least CloudFlare doesn't give me issues:

if i try this:

try:
host = os.environ['REMOTE_ADDR'][0]
except socket.gaierror:
host = UnResolved

then i get no errors and a valid ip back

but the above fails.

I don't know how to catch the exception with OSError.

i know only this two:

except socket.gaierror:
except socket.herror

both fail.

--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Important features for editors

2013-07-04 Thread MRAB

On 04/07/2013 14:22, Tim Chase wrote:

On 2013-07-04 05:02, Dave Angel wrote:
[snip an excellent list of things to look for in an editor]

Also,

- the ability to perform changes in bulk, especially across files.
   Often, this is done with the ability to record/playback macros,
   though some editors have multiple insertion/edit cursors; others
   allow for performing a bulk-change command across the entire file
   or list of files.

- folding (the ability to collapse multiple lines of text down to one
   line).  Especially if there are various ways to do it (manual
   folding, language-block folding, folding by indentation)

- multiple clipboard buffers/registers

- multiple bookmarks

- the ability to interact with external programs (piping a portion of
   a file through an external utility)

- a good community around it in case you have questions

- easy navigation to important things in your file (where
   important may vary based on file-type, but may include function
   definitions, paragraph boundaries, matching
   paren/bracket/brace/tag, etc)

Other nice-to-haves include

- split window editing
- tabbed windows
- Unicode support (including various encodings)


It's 2013, yet Unicode support is merely a nice-to-have?


- vimgolf.com ;-)


Candidates?
emacs  - standard on most OS's, available for Windows from


And I'll put in a plug for Vim.



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


Re: Important features for editors

2013-07-04 Thread William Ray Wing
On Jul 4, 2013, at 9:22 AM, Tim Chase python.l...@tim.thechases.com wrote:

 On 2013-07-04 05:02, Dave Angel wrote:
 [snip an excellent list of things to look for in an editor]
 
 Also, 
 
 - the ability to perform changes in bulk, especially across files.
  Often, this is done with the ability to record/playback macros,
  though some editors have multiple insertion/edit cursors; others
  allow for performing a bulk-change command across the entire file
  or list of files.
 

To Tim's and Dave's excellent lists let me add one more feature that I find 
useful:
  the ability to bulk-search through all files in a folder/directory/project 
for a word
  or phrase, display the hits and then selectively or optionally do a replace 
on each
  hit in the displayed list.  In effect, this is an interactive extension of 
the bulk
  search and replace Tim lists above. 


 - folding (the ability to collapse multiple lines of text down to one
  line).  Especially if there are various ways to do it (manual
  folding, language-block folding, folding by indentation)

Yes, yes, yes.  It may simply be a reflection of my poor programming style (grow
  by accretion, wait way too long to refactor), but this is a big help in 
following
  program logic.

 
 - multiple clipboard buffers/registers
 
 - multiple bookmarks
 
 - the ability to interact with external programs (piping a portion of
  a file through an external utility)
 

And in particular, the ability to preview a chunk of html in a browser.

 - a good community around it in case you have questions
 
 - easy navigation to important things in your file (where
  important may vary based on file-type, but may include function
  definitions, paragraph boundaries, matching
  paren/bracket/brace/tag, etc)
 
 Other nice-to-haves include
 
 - split window editing
 - tabbed windows
 - Unicode support (including various encodings)
 - vimgolf.com ;-)
 
 Candidates?
emacs  - standard on most OS's, available for Windows from
 
 And I'll put in a plug for Vim.
 
 -tkc
 
 
 
 
 
 
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list

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


Fwd: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος Γκρ33κ




 Αρχικό μήνυμα 
Θέμα: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in 
position 0: invalid start byte

Ημερομηνία: Thu, 04 Jul 2013 14:34:42 +0100
Από: MRAB pyt...@mrabarnett.plus.com
Απάντηση: python-list@python.org
Προς: python-list@python.org
Ομάδες συζήτησης: comp.lang.python
Αναφορές: kr3c7k$tjs$2...@news.grnet.gr 
n3tfaa-eqh@satorlaser.homedns.org kr3jai$jn0$4...@news.grnet.gr 
mailman.4219.1372935984.3114.python-l...@python.org 
kr3mnq$jn0$6...@news.grnet.gr 
mailman.4222.1372939645.3114.python-l...@python.org 
kr3r7b$9h4$2...@news.grnet.gr


On 04/07/2013 13:52, Νίκος wrote:

Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:

Also, try printing out ascii(os.environ['REMOTE_ADDR']).


'108.162.229.97' is the result of:

print( ascii(os.environ['REMOTE_ADDR']) )

Seems perfectly valid. and also have a PTR record, so that leaved us
clueless about the internal server error.


For me, socket.gethostbyaddr('108.162.229.97') raises socket.herror,
which is also a subclass of OSError from Python 3.3 onwards.

Tell me how i should write the try/except please.
--
What is now proved was at first only imagined!


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


Re: Coping with cyclic imports

2013-07-04 Thread Oscar Benjamin
On 4 July 2013 13:48,  kanchan.n.maha...@gmail.com wrote:
 On Tuesday, April 8, 2008 10:06:46 PM UTC+2, Torsten Bronger wrote:
[snip]

 If you do import foo inside bar and import bar inside foo, it will work 
 fine. By the time anything actually runs, both modules will be fully loaded 
 and will have references to each other.

 The problem is when instead you do from foo import abc and from bar import 
 xyz. Because now each module requires the other module to already be 
 compiled (so that the name we are importing exists) before it can be compiled.

 from
 http://stackoverflow.com/questions/744373/circular-or-cyclic-imports-in-python

Is there some reason you're responding to a post from 5 years ago?

Or is it just a joke that you've created a cyclic import advice link
by referring to a SO question where the top answer is actually a quote
linking back to the previous post in this same thread?


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


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread MRAB

On 04/07/2013 14:38, Νίκος Γκρ33κ wrote:

Στις 4/7/2013 4:34 μμ, ο/η MRAB έγραψε:

On 04/07/2013 13:47, Νίκος wrote:

Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε:

On 04/07/2013 12:36, Νίκος wrote:

Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε:

On 04/07/2013 11:38, Νίκος wrote:

Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε:

Am 04.07.2013 10:37, schrieb Νίκος:

I just started to have this error without changing nothing


Well, undo the nothing that you didn't change. ;)


UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in
position 0:
invalid start byte
[Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97]
Premature
end
of script headers: metrites.py

Why cant it decode the starting byte? what starting byte is that?


It's the 0xb6 but it's expecting the starting byte of a UTF-8
sequence.
Please do some research on UTF-8, that should clear it up. You could
also search for common causes of that error.


So you are also suggesting that what gesthostbyaddr() returns is not
utf-8 encoded too?

What character is 0xb6 anyways?


Well, it's from a bytestring, so you'll have to specify what encoding
you're using! (It clearly isn't UTF-8.)

If it's ISO-8859-7 (what you've previously referred to as
greek-iso),
then:

  import unicodedata
  unicodedata.name(b\xb6.decode(ISO-8859-7))
'GREEK CAPITAL LETTER ALPHA WITH TONOS'

You'll need to find out where that bytestring is coming from.


Right.
But nowhere in my script(metrites.py) i use an 'Ά' so i really have no
clue where this is coming from.

And you are right if it was a byte came from an utf-8 encoding scheme
then it would be automatically decoded.

The only thing i can say for use is that this problem a[[ear only
when i
cloudflare my domain superhost.gr

If i un-cloudlflare it it cease to display errors.

Can you tell me hpw to write the following properly:

host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or
'UnResolved'

so even if the function fails unresolved to be returned back?
Somehow i need to capture the error.

Or it dosnt have to do it the or operand will be returned?


If gethostbyaddr fails, it raises socket.gaierror, (which, from Python
3.3 onwards, is a subclass of OSError), so try catching that, setting
'host' to 'UnResolved' if it's raised.

Also, try printing out ascii(os.environ['REMOTE_ADDR']).



I have followed your suggestion by trying this:

try:
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except socket.gaierror:
host = UnResolved

and then re-cloudlflared superhost.gr domain

http://superhost.gr/ gives internal server error.


Try catching OSError instead. (As I said, from Python 3.3,
socket.gaierror is a subclass of it.)



At least CloudFlare doesn't give me issues:

if i try this:

try:
host = os.environ['REMOTE_ADDR'][0]
except socket.gaierror:
host = UnResolved


It's pointless trying to catch a socket exception here because you're
not using a socket, you're just getting a string from an environment
variable.


then i get no errors and a valid ip back

but the above fails.

I don't know how to catch the exception with OSError.

i know only this two:

except socket.gaierror:
except socket.herror

both fail.


What do you mean I don't know how to catch the exception with
OSError? You've tried except socket.gaierror and except
socket.herror, well just write except OSError instead!

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


Re: Coping with cyclic imports

2013-07-04 Thread kanchan . n . mahajan
On Thursday, July 4, 2013 5:03:20 PM UTC+2, Oscar Benjamin wrote:
 On 4 July 2013 13:48,  kanchan.n.maha...@gmail.com wrote:
 
  On Tuesday, April 8, 2008 10:06:46 PM UTC+2, Torsten Bronger wrote:
 
 [snip]
 
 
 
  If you do import foo inside bar and import bar inside foo, it will work 
  fine. By the time anything actually runs, both modules will be fully loaded 
  and will have references to each other.
 
 
 
  The problem is when instead you do from foo import abc and from bar 
  import xyz. Because now each module requires the other module to already 
  be compiled (so that the name we are importing exists) before it can be 
  compiled.
 
 
 
  from
 
  http://stackoverflow.com/questions/744373/circular-or-cyclic-imports-in-python
 
 
 
 Is there some reason you're responding to a post from 5 years ago?
 
 
 
 Or is it just a joke that you've created a cyclic import advice link
 
 by referring to a SO question where the top answer is actually a quote
 
 linking back to the previous post in this same thread?
 
 
 
 
 
 Oscar

Well I am just a new to python
and sorry i didnt see the date of the question
and guessing if people find this post first then it would be helpful for them 
to get a good answer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?

2013-07-04 Thread memilanuk

On 07/04/2013 06:23 AM, Aseem Bansal wrote:

I want to start GUI development using Tkinter in Python 2.7.5.

I have been searching all over google but couldn't find any IDE that
has drag-and-drop feature for Python GUI development.



For Tkinter, no luck.  The general consensus always seems to be that 
Tkinter and/or apps written using it tend to be simple enough to not 
really need that much 'help'.  Being a new(er) user I kind of disagree, 
as I think having to 'hand code' everything for the gui library included 
with Python detracts somewhat from its appeal to new users in that 
particular area.


Qt Creator is available for PyQt, which may be a better pick for you 
depending on what you want to do.  It does have a drag-n-drop interface 
that is very slick, but it generates a .ui file that still needs to be 
translated into a python module and imported into your main 'program' 
file - but it takes a *lot* of the tedium out of creating a user 
interface more complicated than a simple dialog window.


HTH,

Monte


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


Re: Important features for editors

2013-07-04 Thread Steve Simmons
rusi rustompm...@gmail.com wrote:

On Thursday, July 4, 2013 7:03:19 PM UTC+5:30, Steve Simmons wrote:
 Boy oh boy! You really are a slow learner Nicos. You have just
offered to 
 commit a crime and to include dozens of others in that crime ON A
PUBLIC 
 FORUM. Please think before you post. 

For the record Steve, let me say, I find Robert Kern's objection barely
sufficient.

And yours less than that.

Note that you are not objecting to the crime but to the public
expression of it.
Just look at your objection from the angle of a police officer, and you
will see that it can certainly be construed as abetment/collusion (or
whatever is the legalistic jargon. Obviously IANAL)

For the sake of covering my own arse let me say:
1. I have earlier described Nikos as a petty-criminal and consider
myself justified.
2. I have earlier described condoning him as collusion and I reiterate
that claim.

And I add
3. The collective actions of this list will help determine further
whether he climbs or descends the criminal ladder.

Beyond that I reiterate what I said earlier in this thread: These
discussions  'in-band' are counter-productive.

Setting up something like an invite-only yahoo or google group or some
such to discuss this is free and takes 5 minutes.

I would have offered to do it but some people like Joshua Landau seem
to think I am interested in world (aka Python-list) domination so not
offering.
I was actually going to suggest that Steven d'Aprano do it. However
before I could do that, he said (in CoC thread) that policing is not
possible. Saddens me...

So I am suggesting you do it.

If I am invited I will contribute my 2c. If not, no objection: I dont
consider myself a very important member of this list.

And yes: I hope you will consider rewording your objection, if not
anything to cover your own you-know-what-where!!
-- 
http://mail.python.org/mailman/listinfo/python-list

Rusi,
Frankly, I don't give a tinkers cuss whether Nicos gets a visit from the 
police, FAST or the Greek secret service.   Like too many others, I gave him 
some advice and within 24 hours he has demonstrated that he didn't see any 
value in that advice.  Fair enough, it's not my problem. 
For my part, I have pointed out the folly of his ways and now reiterated, maybe 
too politely, that he has let himself down again.  Robert Kern had already 
given him a blunt response that such communication is unwelcome and I felt no 
need to reinforce it. 
If the police or any other authority are 'on my trail' they are welcome to 
visit my house where they will find absolutely no trace of any kind of crime 
(unless they check how badly I've ignored the need to redecorate). And just for 
the record, the lack of evidence of crime will not be because I covered it up 
really well but because there ain't none guv.
I absolutely agree that the ongoing debate about Nicos' behaviour and the finer 
points of how various members of this list have reacted has become more than a 
little tiresome and it is high time it moved to another medium.  However, with 
no guidelines in place and no sanctions available, any discussion - on or off 
list - had precious little value. I still think the CoC idea has some merit but 
with just a few notable exceptions the response has been pretty lukewarm. 
Likewise,  I don't contribute much to this list - as a newcomer to python I 
don't have to much to offer - but I mostly enjoy being a small part of it and I 
would be happy to make a contribution to the CoC if I felt that the end result 
would be both useful and welcomed. 

Steve


Sent from a Galaxy far far away-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default scope of variables

2013-07-04 Thread Wayne Werner

On Thu, 4 Jul 2013, Steven D'Aprano wrote:


[1] Based on empirical evidence that Python supports names with length at
least up to one million characters long, and assuming that each character
can be an ASCII letter, digit or underscore.



The specification *does* state unlimited length:

http://docs.python.org/release/2.5.2/ref/identifiers.html

Though practicality beats purity.

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


Re: Important features for editors

2013-07-04 Thread Steven D'Aprano
On Thu, 04 Jul 2013 12:01:26 +0100, Robert Kern wrote:

 On 2013-07-04 10:14, Νίκος wrote:
 
 If you guys want to use it i can send you a patch for it. I know its
 illegal thing to say but it will help you use it without buying it.
 
 Please do not use this forum to make such offers.


Thank you Robert.



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


Re: Important features for editors

2013-07-04 Thread Steven D'Aprano
On Thu, 04 Jul 2013 07:02:26 -0700, rusi wrote:

 On Thursday, July 4, 2013 7:03:19 PM UTC+5:30, Steve Simmons wrote:
 Boy oh boy! You really are a slow learner Nicos. You have just offered
 to commit a crime and to include dozens of others in that crime ON A
 PUBLIC FORUM. Please think before you post.
 
 For the record Steve, let me say, I find Robert Kern's objection barely
 sufficient.
 
 And yours less than that.
 
 Note that you are not objecting to the crime 

Which crime is that? Presumably you mean an actual criminal felony, not a 
mere civil offence. Under which jurisdiction?


 but to the public
 expression of it. Just look at your objection from the angle of a police
 officer, and you will see that it can certainly be construed as
 abetment/collusion 

If piracy is a crime, and not just a civil offence, then surely so is 
libel. You have just accused Steve Simmons of collusion in a felony, 
based on absolutely no evidence at all. That's as clear a case of libel 
as I've ever seen. Although I'm not sure that the damages should be 
terribly high -- there's little evidence that anyone treats your 
ridiculously exaggerated claims about other people's supposed crimes as 
anything but hot air.

But, putting damages aside, according to what passes for the reasoning 
that you have demonstrated here, your committing libel would make you 
equally a petty criminal as Nikos.


Speaking of petty, this whole witch-hunt is getting ridiculous. Don't you 
have something more productive to do? Accusing people of colluding in 
crimes because they fail to be sufficiently zealous in objecting to the 
crime is nuts.


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


Re: First attempt at a Python prog (Chess)

2013-07-04 Thread Chris Hinsley

On 2013-02-13 23:25:09 +, Chris Hinsley said:


New to Python, which I really like BTW.

First serious prog. Hope you like it. I know it needs a 'can't move if 
your King would be put into check' test. But the weighted value of the 
King piece does a surprising emergent job.


New version with better search and hopefully a little better Python. I 
know it's still far from fully correct and it'll never best Gary 
Kasperov. :)


With pypy on my Macbook I can go to 6 PLY with resonable performance 
now due to the alpha-beta pruneing.


Regards

#!/usr/bin/python -tt
# -*- coding: utf-8 -*-
# Copyright (C) 2013 Chris Hinsley, GPL V3 License

import sys
import random
import os

PLY = 5

EMPTY = 0
WHITE = 1
BLACK = -1
NO_CAPTURE = 2
MAY_CAPTURE = 3
MUST_CAPTURE = 4

piece_type = {' ' : EMPTY, 'K' : BLACK, 'Q' : BLACK, 'R' : BLACK, 'B' : 
BLACK, 'N' : BLACK, 'P' : BLACK, \
   'k' : WHITE, 'q' : WHITE, 'r' : WHITE, 'b' : WHITE, 'n' : 
WHITE, 'p' : WHITE}


def display_board(board):
   print '  a   b   c   d   e   f   g   h'
   print '+---+---+---+---+---+---+---+---+'
   for row in range(8):
   for col in range(8):
   print '| %c' % board[row * 8 + col],
   print '|', 8 - row
   print '+---+---+---+---+---+---+---+---+'

def piece_moves(board, index, dx, dy, capture_flag, distance):
   piece = board[index]
   type = piece_type[piece]
   cy, cx = divmod(index, 8)
   for step in range(distance):
   nx = cx + (dx * (step + 1))
   ny = cy + (dy * (step + 1))
   if (0 = nx  8) and (0 = ny  8):
   newindex = ny * 8 + nx
   newpiece = board[newindex]
   newtype = piece_type[newpiece]
   if capture_flag == MUST_CAPTURE:
   if newtype != EMPTY and newtype != type:
   board[index] = ' '
   if (ny == 0 or ny == 7) and piece in 'Pp':
   for promote in 'QRBN' if type == BLACK else 'qrbn':
   board[newindex] = promote
   yield board
   else:
   board[newindex] = piece
   yield board
   board[index], board[newindex] = piece, newpiece
   elif capture_flag == MAY_CAPTURE:
   if newtype == EMPTY:
   board[index], board[newindex] = ' ', piece
   yield board
   board[index], board[newindex] = piece, newpiece
   elif newtype != type:
   board[index], board[newindex] = ' ', piece
   yield board
   board[index], board[newindex] = piece, newpiece
   break
   else:
   break
   elif newtype == EMPTY:
   board[index] = ' '
   if (ny == 0 or ny == 7) and piece in 'Pp':
   for promote in 'QRBN' if type == BLACK else 'qrbn':
   board[newindex] = promote
   yield board
   else:
   board[newindex] = piece
   yield board
   board[index], board[newindex] = piece, newpiece
   else:
   break
   else:
   break

def pawn_moves(board, index, options):
   for x, y, flag, distance in options:
   for new_board in piece_moves(board, index, x, y, flag, distance):
   yield new_board

def other_moves(board, index, options, distance):
   for x, y in options:
   for new_board in piece_moves(board, index, x, y, MAY_CAPTURE, 
distance):

   yield new_board

def black_pawn_moves(board, index):
   distance = 2 if index in range(8, 16) else 1
   for new_board in pawn_moves(board, index, [(0, 1, NO_CAPTURE, 
distance), (-1, 1, MUST_CAPTURE, 1), (1, 1, MUST_CAPTURE, 1)]):

   yield new_board

def white_pawn_moves(board, index):
   distance = 2 if index in range(48, 56) else 1
   for new_board in pawn_moves(board, index, [(0, -1, NO_CAPTURE, 
distance), (-1, -1, MUST_CAPTURE, 1), (1, -1, MUST_CAPTURE, 1)]):

   yield new_board

def rook_moves(board, index):
   for new_board in other_moves(board, index, [(0, -1), (-1, 0), (0, 
1), (1, 0)], 7):

   yield new_board

def bishop_moves(board, index):
   for new_board in other_moves(board, index, [(-1, -1), (-1, 1), (1, 
1), (1, -1)], 7):

   yield new_board

def knight_moves(board, index):
   for new_board in other_moves(board, index, [(-2, 1), (2, -1), (2, 
1), (-1, -2), (-1, 2), (1, -2), (1, 2)], 1):

   yield new_board

def queen_moves(board, index):
   for new_board in bishop_moves(board, index):
   yield new_board
   for new_board in rook_moves(board, index):
   yield new_board

def king_moves(board, index):
   for new_board in other_moves(board, index, [(0, -1), (-1, 0), (0, 
1), (1, 0), (-1, -1), (-1, 1), (1, 1), (1, -1)], 1):

   yield new_board

moves = {'P' : black_pawn_moves, 'p' : white_pawn_moves, \
   'R' : rook_moves, 'r' : rook_moves, \
   'B' : 

Re: Default scope of variables

2013-07-04 Thread Steven D'Aprano
On Thu, 04 Jul 2013 03:06:25 -0400, Dave Angel wrote:

 On 07/04/2013 01:32 AM, Steven D'Aprano wrote:

SNIP

 Well, if I ever have more than 63,000,000 variables[1] in a function,
 I'll keep that in mind.

  SNIP

 [1] Based on empirical evidence that Python supports names with length
 at least up to one million characters long, and assuming that each
 character can be an ASCII letter, digit or underscore.


 Well, the number wouldn't be 63,000,000.  Rather it'd be 63**100
 
 I probably have it wrong, but I think that looks like:
 
 
859,122,207,646,748,720,415,212,786,780,258,721,683,540,870,960,267,706,738,947,655,539,422,295,787,680,882,091,181,482,626,114,653,152,637,456,091,641,990,601,474,111,018,521,295,858,424,750,289,461,372,414,431,396,326,232,796,267,104,001
 
 variables.  (The number has 180 digits)


I think that's more than 63,000,000 :-)


Thanks Dave and Peter for the correction.


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


Re: Important features for editors

2013-07-04 Thread rurpy
On 07/04/2013 08:24 AM, MRAB wrote:
 On 04/07/2013 14:22, Tim Chase wrote:
 On 2013-07-04 05:02, Dave Angel wrote:
 [snip an excellent list of things to look for in an editor]

 It's 2013, yet Unicode support is merely a nice-to-have?
 
I agree that this is pretty important.  Even if you don't
have to deal with Unicode today, the chances are good that 
you will need to, if only in an occasional way, in the 
future.

One thing not mentioned (sorry if I missed it) that I
use more than many of the features that have been mentioned
is some form of advanced search/replace.  I.e. something
that can do regular expression searches and replaces 
including multiline ones.

Another feature I find necessary is very fast start up time
since I open an editor hundreds of times a day.

Because advanced features and fast startup seem to be mutually
exclusive, I often use two editors, a simple but quick starting
one like Gedit on Linux or Notepad on Windows for 90% of 
routine editing and Emacs for the the other 10% when I need 
to do something more powerful.  But as a disclaimer I should 
add that I do not spend 8+ hours a day doing nothing but 
programming so YMMV.

BTW, the group is currently having a problem both with
trolls and with regulars here that bite at every baited 
hook that drifts past their screen.  There seems to nothing
to be done other than ignore the obnoxious posts but I am
sorry they have infiltrated your discussion.  Hopefully
this comment won't add to the problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Νίκος Γκρ33κ

Στις 4/7/2013 6:10 μμ, ο/η MRAB έγραψε:

What do you mean I don't know how to catch the exception with
OSError? You've tried except socket.gaierror and except
socket.herror, well just write except OSError instead!



try:
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except OSError:
host = UnResolved

produces also an internal server error.

Are you sure is just except OSError ?

seems very general...

--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


RE: Decorator help

2013-07-04 Thread Joseph L. Casale
Well, technically it's

func.func_closure[0].cell_contents.__name__

but of course you cannot know that for the general case.

Hah, I admit I lacked perseverance in looking at this in PyCharms debugger as I 
missed
that.

Much appreciated!
jlc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Important features for editors

2013-07-04 Thread Steve Simmons
To Rurpy and cutems93,

My apologies too.  I reacted before I thought about creating a new thread.

To your question:  One thing that I don't use daily but find very useful to
have in an editor is  'Hex View' (or better yet a 'Hex Editor').

Whilst it has been 'dissed' recently on this list, I like Notepad++ for
everyday editing but if I'm head-down in a particular language, I prefer to
be in an IDE.

Steve


On Thu, Jul 4, 2013 at 4:56 PM, ru...@yahoo.com wrote:

 On 07/04/2013 08:24 AM, MRAB wrote:
  On 04/07/2013 14:22, Tim Chase wrote:
  On 2013-07-04 05:02, Dave Angel wrote:
  [snip an excellent list of things to look for in an editor]

  It's 2013, yet Unicode support is merely a nice-to-have?

 I agree that this is pretty important.  Even if you don't
 have to deal with Unicode today, the chances are good that
 you will need to, if only in an occasional way, in the
 future.

 One thing not mentioned (sorry if I missed it) that I
 use more than many of the features that have been mentioned
 is some form of advanced search/replace.  I.e. something
 that can do regular expression searches and replaces
 including multiline ones.

 Another feature I find necessary is very fast start up time
 since I open an editor hundreds of times a day.

 Because advanced features and fast startup seem to be mutually
 exclusive, I often use two editors, a simple but quick starting
 one like Gedit on Linux or Notepad on Windows for 90% of
 routine editing and Emacs for the the other 10% when I need
 to do something more powerful.  But as a disclaimer I should
 add that I do not spend 8+ hours a day doing nothing but
 programming so YMMV.

 BTW, the group is currently having a problem both with
 trolls and with regulars here that bite at every baited
 hook that drifts past their screen.  There seems to nothing
 to be done other than ignore the obnoxious posts but I am
 sorry they have infiltrated your discussion.  Hopefully
 this comment won't add to the problem.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Default scope of variables

2013-07-04 Thread Steven D'Aprano
On Thu, 04 Jul 2013 15:47:57 +1000, Chris Angelico wrote:

 On Thu, Jul 4, 2013 at 3:32 PM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:
 Accidental shadowing can be a problem, but I've never heard of anyone
 saying that they were *forced* to shadow a global they needed access
 to. Just pick a different name.
 
 Here's one example of shadowing that comes from a C++ project at work. I
 have a class that represents a database transaction (constructing it
 begins a transaction, it has methods for doing queries, and its
 destructor rolls back). 

When the object finally gets garbage collected, doesn't that mean the 
last transaction will be rolled back?

 There's also a class for a subtransation (same
 thing, but it uses savepoints within the transaction). So to bracket a
 piece of code in a subtransaction, I want to declare a new
 subtransaction object with the same name as the outer transaction
 object, and then dispose of it and reveal the original. There will
 always be an object called trans, and it will always be the
 appropriate transaction to do queries on, but it'll change what it is.

You don't need to introduce such scoping rules for variables for that use-
case. We have namespaces (classes) for that sort of thing :-) 

Python 3.3's ChainMap is probably a better solution, but here's another 
way to get the same sort of behaviour:


def function():
class Namespace:
# Set a class attribute.
trans = Transaction()
ns = Namespace()
do_stuff_with(ns.trans)
# Enter a subtransaction.
ns.trans = Subtransaction()
do_stuff_with(ns.trans)
del ns.trans
do_stuff_with(ns.trans)


Yes, it looks weird to see ns.trans used immediately after deleting it, 
but that's because it is a weird (or at least unusual) use-case.


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


Re: Default scope of variables

2013-07-04 Thread Rotwang

Sorry to be OT, but this is sending my pedantry glands haywire:

On 04/07/2013 08:06, Dave Angel wrote:

On 07/04/2013 01:32 AM, Steven D'Aprano wrote:



   SNIP


Well, if I ever have more than 63,000,000 variables[1] in a function,
I'll keep that in mind.


 SNIP


[1] Based on empirical evidence that Python supports names with length at
least up to one million characters long, and assuming that each character
can be an ASCII letter, digit or underscore.



Well, the number wouldn't be 63,000,000.  Rather it'd be 63**100

I probably have it wrong, but I think that looks like:

859,122,[etc.]


variables.  (The number has 180 digits)


That's 63**100. Note that 10**100 has 101 digits, and is 
somewhat smaller than 63**100.


Anyway, none of the calculations that has been given takes into account 
the fact that names can be /less/ than one million characters long. The 
actual number of non-empty strings of length at most 100 characters, 
that consist only of ascii letters, digits or underscores, and that 
don't start with a digit, is


sum(53*63**i for i in range(100)) == 53*(63**100 - 1)//62


It's perhaps worth mentioning that some non-ascii characters are allowed 
in identifiers in Python 3, though I don't know which ones.

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


Re: Default scope of variables

2013-07-04 Thread Chris Angelico
On Fri, Jul 5, 2013 at 2:38 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 On Thu, 04 Jul 2013 15:47:57 +1000, Chris Angelico wrote:
 Here's one example of shadowing that comes from a C++ project at work. I
 have a class that represents a database transaction (constructing it
 begins a transaction, it has methods for doing queries, and its
 destructor rolls back).

 When the object finally gets garbage collected, doesn't that mean the
 last transaction will be rolled back?

Oh. Uhm... ahh... it would have helped to mention that it also has a
commit() method! But yes, that's correct; if the object expires (this
is C++, so it's guaranteed to call the destructor at that close brace
- none of the Python vagueness about when __del__ is called) without
commit() being called, then the transaction will be rolled back. And
since this is PostgreSQL we use, the same applies if the process is
SIGKILLed or the power fails. If commit() doesn't happen, neither does
the transaction. (There are a few actions the program can take that
are deliberately non-transactional - log entries of various sorts,
mainly - but everything else is guarded in this way.)

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


Illegal suggestions on python list

2013-07-04 Thread Rustom Mody
On Thu, Jul 4, 2013 at 9:16 PM, Steven D'Aprano 
steve+comp.lang.pyt...@pearwood.info wrote:

 On Thu, 04 Jul 2013 07:02:26 -0700, rusi wrote:

  On Thursday, July 4, 2013 7:03:19 PM UTC+5:30, Steve Simmons wrote:
  Boy oh boy! You really are a slow learner Nicos. You have just offered
  to commit a crime and to include dozens of others in that crime ON A
  PUBLIC FORUM. Please think before you post.
 
  For the record Steve, let me say, I find Robert Kern's objection barely
  sufficient.
 
  And yours less than that.
 
  Note that you are not objecting to the crime

 Which crime is that? Presumably you mean an actual criminal felony, not a
 mere civil offence. Under which jurisdiction?


  but to the public
  expression of it. Just look at your objection from the angle of a police
  officer, and you will see that it can certainly be construed as
  abetment/collusion

 If piracy is a crime, and not just a civil offence, then surely so is
 libel. You have just accused Steve Simmons of collusion in a felony,
 based on absolutely no evidence at all. That's as clear a case of libel
 as I've ever seen. Although I'm not sure that the damages should be
 terribly high -- there's little evidence that anyone treats your
 ridiculously exaggerated claims about other people's supposed crimes as
 anything but hot air.

 But, putting damages aside, according to what passes for the reasoning
 that you have demonstrated here, your committing libel would make you
 equally a petty criminal as Nikos.


 Speaking of petty, this whole witch-hunt is getting ridiculous. Don't you
 have something more productive to do? Accusing people of colluding in
 crimes because they fail to be sufficiently zealous in objecting to the
 crime is nuts.


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



You've got your OO class hierarchy mixed up and then imposing that on me.

See
http://www.nolo.com/legal-encyclopedia/crimes-felonies-misdemeanors-infractions-classification-33814.html

I did not say or suggest felony.
Maybe misdemeanor or infarction. Dunno which. IANAL...
-- 
http://mail.python.org/mailman/listinfo/python-list


How is this evaluated

2013-07-04 Thread Arturo B
I'm making this exercise: (Python 3.3)

Write a function translate() that will translate a text into rövarspråket 
(Swedish for robber's language). That is, double every consonant and place an 
occurrence of o in between. For example, translate(this is fun) should 
return the string tothohisos isos fofunon.

So I tried to solved it, but I couldn't, so I found many answers, but I 
selected this:

def translate(s):
  consonants = 'bcdfghjklmnpqrstvwxz'
  return ''.join(l + 'o' + l if l in consonants else l for l in s)

print(translate('hello code solver'))


OUTPUT:
'hohelollolo cocodode sosololvoveror'

__
So I want to question:
How is the 

if 'h' in consonants else 'h' for 'h' in s

part evaluated? (step by step please :P )

''.join('h' + 'o' + 'h' if 'h' in consonants else 'h' for 'h' in s)

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


Convert SOAP response (ArrayOfInt) to Python list

2013-07-04 Thread robert . winkler
Thanks to the OSA library, which works for SOAP requests with Python 3.x, I can 
now use SOAP services at http://www.chemspider.com.

The results structure is 
  GetAsyncSearchResultResult
intint/int
intint/int
  /GetAsyncSearchResultResult

The result is a list of accession numbers (which correspond to chemical 
compounds) and I get them in the following format:

(ArrayOfInt){
int[] = [
 5744,
 69182,
 292,
 68027,
 3404131,
 82616,
 18280,
 11200,
 704646,
 543430
 ...
 ]
}

How could I transform this to a simple python list?

[5744, 69182, 292,68027, 3404131, 82616, 18280, 11200, 704646, 543430 ...]

Conversion to a numpy array (and subsequent list(), or similar) does not solve 
the problem, since the structure is maintained; the numpy.shape returns ().

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


Re: How is this evaluated

2013-07-04 Thread Antoon Pardon

Op 04-07-13 19:20, Arturo B schreef:

I'm making this exercise: (Python 3.3)

Write a function translate() that will translate a text into rövarspråket (Swedish for robber's 
language). That is, double every consonant and place an occurrence of o in between. For example, 
translate(this is fun) should return the string tothohisos isos fofunon.

So I tried to solved it, but I couldn't, so I found many answers, but I 
selected this:

def translate(s):
   consonants = 'bcdfghjklmnpqrstvwxz'
   return ''.join(l + 'o' + l if l in consonants else l for l in s)

print(translate('hello code solver'))


OUTPUT:
'hohelollolo cocodode sosololvoveror'

__
So I want to question:
How is the

if 'h' in consonants else 'h' for 'h' in s

part evaluated? (step by step please :P )

''.join('h' + 'o' + 'h' if 'h' in consonants else 'h' for 'h' in s)

Thank you guys


This doesn't make much sence because you substituted a varible for
a character literal, so I'll go with the original.



l + 'o' + l if l in consonants else l for l in s

Evaluate this expression:

l + 'o' + l if l in consonants else l

for each l in s (so for each letter that in s).



l + 'o' + l if l in consonants else l

if l is part of the consonants produce l + 'o' + l
otherwise just produce l.


Hope this helps.

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


Re: How is this evaluated

2013-07-04 Thread newspost2012
Am Donnerstag, 4. Juli 2013 19:20:43 UTC+2 schrieb Arturo B:
 ...
 So I want to question:
 How is the 
 
 if 'h' in consonants else 'h' for 'h' in s
 
 part evaluated? (step by step please :P )

Although new to python I think I can solve this (if no one contradicts, I can 
guess that I understood it :-) ):

Take every letter from the string, one after the other, (for l in s).
If you can find the letter in the string constants (if l in constants) then 
take it, append an o and then the letter again and return it (l + 'o' + l) if 
not, return the letter as it is (else l).

Or in applicable order:
take 'h' append 'o' append 'h' and return this, if you can find 'h' in 
constants, if not return just 'h' (and do this for every letter in string s)

hth,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Illegal suggestions on python list

2013-07-04 Thread feedthetroll
Am Donnerstag, 4. Juli 2013 19:10:07 UTC+2 schrieb rusi:
 On Thu, Jul 4, 2013 at 9:16 PM, Steven D'Aprano 
 steve+comp@pearwood.info wrote:
 On Thu, 04 Jul 2013 07:02:26 -0700, rusi wrote:
 ...
 Note that you are not objecting to the crime

 Which crime is that? Presumably you mean an actual criminal felony, not a
 mere civil offence. Under which jurisdiction?
 
 You've got your OO class hierarchy mixed up and then imposing that on me.
 See
 http://www.nolo.com/legal-encyclopedia/crimes-felonies-misdemeanors-
 infractions-classification-33814.html

Oh, sorry, we forgot, that the US legal system is the only one applicable to 
the internt (and of course to the whole world). 

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


Re: How is this evaluated

2013-07-04 Thread Jussi Piitulainen
Arturo B writes:

 I'm making this exercise: (Python 3.3)
 
 Write a function translate() that will translate a text into
 rövarspråket (Swedish for robber's language). That is, double
 every consonant and place an occurrence of o in between. For
 example, translate(this is fun) should return the string
 tothohisos isos fofunon.
 
 So I tried to solved it, but I couldn't, so I found many answers,
 but I selected this:
 
 def translate(s):
   consonants = 'bcdfghjklmnpqrstvwxz'
   return ''.join(l + 'o' + l if l in consonants else l for l in s)
 
 print(translate('hello code solver'))
 
 
 OUTPUT:
 'hohelollolo cocodode sosololvoveror'
 
 __
 So I want to question:
 How is the 
 
 if 'h' in consonants else 'h' for 'h' in s
 
 part evaluated? (step by step please :P )

That's nonsense in two different ways. The actual expression in the
solution you found makes sense. It's a generator expression of this
form:

   expression for l in s

And the expression in it is this conditional expression:

   l + 'o' + l if l in consonants else l

The value of this conditional expression is (l + 'o' + l) if l is in
consontants, for example 'tot' if l == 't'; else it is just l, for
example 'i' if l == 'i'.

Fully parenthesised the whole expression is this:

   ((l + 'o' + l) if (l in consonants) else l) for l in s

The value of this expression yields the values like 'tot' and 'hoh'
and 'i' for each letter l in s in turn.

 ''.join('h' + 'o' + 'h' if 'h' in consonants else 'h' for 'h' in s)

This is still nonsense. To make sense, replace each 'h' with h.

Then ''.join can eat up the values of a generator expression to
produce the string like 'tothohi...'.

You can experiment with the components of this complicated expression:

list(x for x in 'plaintext')

'x' if True else 'y'
'x' if False else 'y'

list((x + 'o' if x not in 'aeiouy' else x) for x in 'plaintext')

for x in 'plaintext': print(x + 'o' if x not in 'aeiouy' else x)

I suppose you understand this:

''.join(('tot', 'hoh', 'i', 'sos'))

Note that a similar-looking expression in brackets [] is a list
comprehension; in braces {} it is a set comprehension, or a dictionary
comprehension if the value expression is a key : value pair, with the
colon. And this is not all: there's nesting and filtering, too. The
different uses of the keywords 'for', 'in', 'if', 'else' are a bit
subtle but one sort of learns to see the whole expression.

I tend to use line breaks and parentheses in such expressions:

   ''.join(c + 'o' + c if c in consonants else c
   for c in message)

   ''.join((c + 'o' + c
if c in consonants
else c)
   for c in message)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default scope of variables

2013-07-04 Thread Peter Otten
Rotwang wrote:

 Sorry to be OT, but this is sending my pedantry glands haywire:

We are mostly pedants, too -- so this is well-deserved...
 
 On 04/07/2013 08:06, Dave Angel wrote:
 On 07/04/2013 01:32 AM, Steven D'Aprano wrote:

SNIP

 Well, if I ever have more than 63,000,000 variables[1] in a function,
 I'll keep that in mind.

  SNIP

 [1] Based on empirical evidence that Python supports names with length
 [at
 least up to one million characters long, and assuming that each
 character can be an ASCII letter, digit or underscore.


 Well, the number wouldn't be 63,000,000.  Rather it'd be 63**100

 I probably have it wrong, but I think that looks like:

 859,122,[etc.]


 variables.  (The number has 180 digits)
 
 That's 63**100. Note that 10**100 has 101 digits, and is
 somewhat smaller than 63**100.
 
 Anyway, none of the calculations that has been given takes into account
 the fact that names can be /less/ than one million characters long. 

I think we have a winner ;)

 The
 actual number of non-empty strings of length at most 100 characters,
 that consist only of ascii letters, digits or underscores, and that
 don't start with a digit, is
 
 sum(53*63**i for i in range(100)) == 53*(63**100 - 1)//62

 It's perhaps worth mentioning that some non-ascii characters are allowed
 in identifiers in Python 3, though I don't know which ones.


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


Re: Important features for editors

2013-07-04 Thread Grant Edwards
On 2013-07-04, ?? ni...@superhost.gr wrote:

 If you guys want to use it i can send you a patch for it. I know its
 illegal thing to say but it will help you use it without buying it.

A new low.  Now he's offering to help people steal others' work.

-- 
Grant


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


Re: Important features for editors

2013-07-04 Thread Ferrous Cranus

Στις 4/7/2013 9:40 μμ, ο/η Grant Edwards έγραψε:

On 2013-07-04, ?? ni...@superhost.gr wrote:


If you guys want to use it i can send you a patch for it. I know its
illegal thing to say but it will help you use it without buying it.


A new low.  Now he's offering to help people steal others' work.


Like you never downloaded serials/keygens/patch/cracks for warez and 
torrents websites.


What a hypocritism.my intensions was to help the OP.


--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Ferrous Cranus

Στις 4/7/2013 11:08 μμ, ο/η Dennis Lee Bieber έγραψε:

On Thu, 04 Jul 2013 13:38:09 +0300, ? ni...@superhost.gr declaimed
the following:


What character is 0xb6 anyways?


It depends on the encoding... In EBCDIC it's unassigned. It's a
paragraph mark in ISO-Latin-1 (ISO-8859-1). Apparently also a paragraph
mark in ISO-Latin-9 (ISO-8859-15).

If it is valid in UTF-8, I can't find a reference. It's not a prefix
for a multi-byte character, which implies that the previous byte should
have been something in prefix or another extended byte entry...


try:
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except:
host = Reverse DNS Failed

Is there a way to write the above so i cna print the error return when 
it fails?


--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Lele Gaifax
Ferrous Cranus ni...@superhost.gr writes:

 try:
   host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
 except:
   host = Reverse DNS Failed

 Is there a way to write the above so i cna print the error return when
 it fails?

Try something like

try:
host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
except Exception as e:
host = Reverse DNS Failed
print(e)

?

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Michael Torrie
On 07/04/2013 02:25 PM, Ferrous Cranus wrote:
 try:
   host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
 except:
   host = Reverse DNS Failed
 
 Is there a way to write the above so i cna print the error return when 
 it fails?
 

Do you know what IP address causes the failure?  If so write a little
python program that does the socket.gethostbyaddr and run it on the
command line!  Debugging through the CGI interface sucks.

Have you been writing python tests that you can run on the command line
during your development these last weeks?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Important features for editors

2013-07-04 Thread Tim Chase
On 2013-07-04 15:24, MRAB wrote:
 On 04/07/2013 14:22, Tim Chase wrote:
  Other nice-to-haves include
 
  - Unicode support (including various encodings)
 
 It's 2013, yet Unicode support is merely a nice-to-have?

Yeah, while I use Vim and it's got support, most of what I do
interacts with unicode stuff as escaped rather than in-line.  In
python, it's things like u\u20AC or in HTML/XML using one of the
escaping variants:  #8364; or #x20ac; or even euro;

So I don't feel particularly hampered even if/when I get stuck with
an editor that only speaks lower-ASCII.

That's why I considered it merely nice to have rather than
essential.

-tkc




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


Re: Important features for editors

2013-07-04 Thread Chris Angelico
On Fri, Jul 5, 2013 at 4:52 AM, Ferrous Cranus ni...@superhost.gr wrote:
 Στις 4/7/2013 9:40 μμ, ο/η Grant Edwards έγραψε:

 On 2013-07-04, ?? ni...@superhost.gr wrote:


 If you guys want to use it i can send you a patch for it. I know its
 illegal thing to say but it will help you use it without buying it.


 A new low.  Now he's offering to help people steal others' work.


 Like you never downloaded serials/keygens/patch/cracks for warez and
 torrents websites.

 What a hypocritism.my intensions was to help the OP.

Even if some of us *have* violated license agreements (which you
shouldn't assume is the case - most of us here are happily using free
software), it's still something that you shouldn't advocate in public.
Would you walk into a crowded room and start hawking a Kryptonite gun
(guaranteed to kill Superman, then you can go rob all the banks you
like) regardless of who's listening? No, you sell it quietly on the
black market. You certainly don't say Hey, you guys have robbed banks
before... haven't you?, because that's certainly not going to be true
of everyone, and even if it is, it doesn't change what you've just
offered.

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


Re: Important features for editors

2013-07-04 Thread Jason Swails
On Thu, Jul 4, 2013 at 2:52 PM, Ferrous Cranus ni...@superhost.gr wrote:

 Στις 4/7/2013 9:40 μμ, ο/η Grant Edwards έγραψε:

  On 2013-07-04, ?? ni...@superhost.gr wrote:


 If you guys want to use it i can send you a patch for it. I know its
 illegal thing to say but it will help you use it without buying it.


 A new low.  Now he's offering to help people steal others' work.


 Like you never downloaded serials/keygens/patch/cracks for warez and
 torrents websites.

 What a hypocritism.my intensions was to help the OP.


No, I don't.  Ever.  And I imagine many others on this list are the same
way.  If I don't want to pay asking price for a product, I won't use it.
 Period.  There's an open source solution to almost everything.  Learn to
use that instead.

Since many people on this list are in the business of making software, I'd
be willing to bet you are in the minority here. (The rather despised
minority, based on previous comments).  Even people that strongly believe
all software should be free would avoid Sublime Text (or start an inspired
open source project), not crack it.  Example: look at the history of git.

What you are doing (and offering to help others do in a public forum)
damages the very product you claim to like.  Commercial software is
maintained and improved by the funding provided by product sales, which you
deprive them of by your behavior.

The original offer was misguided at best, but this attempted defense that
casts everyone else down to your level (and avoids admitting wrongdoing) is
reprehensible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Coping with cyclic imports

2013-07-04 Thread Dave Angel

On 07/04/2013 11:11 AM, kanchan.n.maha...@gmail.com wrote:

On Thursday, July 4, 2013 5:03:20 PM UTC+2, Oscar Benjamin wrote:

On 4 July 2013 13:48,  kanchan.n.maha...@gmail.com wrote:


On Tuesday, April 8, 2008 10:06:46 PM UTC+2, Torsten Bronger wrote:


[snip]






If you do import foo inside bar and import bar inside foo, it will work 
fine. By the time anything actually runs, both modules will be fully loaded and will have 
references to each other.







The problem is when instead you do from foo import abc and from bar import 
xyz. Because now each module requires the other module to already be compiled (so that the 
name we are importing exists) before it can be compiled.







from



http://stackoverflow.com/questions/744373/circular-or-cyclic-imports-in-python




Is there some reason you're responding to a post from 5 years ago?



Or is it just a joke that you've created a cyclic import advice link

by referring to a SO question where the top answer is actually a quote

linking back to the previous post in this same thread?





Oscar


Well I am just a new to python
and sorry i didnt see the date of the question
and guessing if people find this post first then it would be helpful for them 
to get a good answer



But the StackOverflow answers for this question aren't good enough.

The problem is much more subtle than those answers imply, unless you 
make certain assumptons about the user's code.  And if I'm going to do 
that, the thing I'm going to figure is that the rational user avoids any 
cyclic imports, period.


if a.py imports b.py, then b.py is not permitted, directly or 
indirectly, to import a.py.  If it does, and something doesn't work, 
then 50 lashes with a wet noodle.


Whenever you find a cycle, try to move the common stuff into a 3rd 
module and have the first two import that one instead of each other.


Avoid having any non-trivial code at the top level, and in no case 
reference anything you've imported from there.  Move everything into 
functions, and don't have any class-static code or data initialization. 
 If you have to break any of these (such as referring to sys.argv), 
make sure that the module you're using is not one that's importing you.


Never, ever import the original script from another module.


--
DaveA

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


Re: DOS or not? [was Re: How to tell Script to use pythonw.exe ?]

2013-07-04 Thread Andrew Berg
On 2013.07.04 09:08, Wayne Werner wrote:
 powershell -ExecutionPolicy Bypass -File ...
 
 
 \o/
 
 Microsoft security at it again! (reminds me a bit of just pushing 
 Cancel to log into windows 98, I think it was)
From an MSDN page linked in one of the answers:
 Now, why is
 
 PowerShell.exe –ExecutionPolicy Bypass –File c:\temp\bad-script.ps1
 
 not a security bug? Ultimately, if bad code has the ability to run this code, 
 it already has control of the machine.
http://blogs.msdn.com/b/powershell/archive/2008/09/30/powershell-s-security-guiding-principles.aspx

If an attacker can run code, he/she already has the capability to well, run 
code.
-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Illegal suggestions on python list

2013-07-04 Thread Chris Angelico
On Fri, Jul 5, 2013 at 3:10 AM, Rustom Mody rustompm...@gmail.com wrote:
 On Thu, Jul 4, 2013 at 9:16 PM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:

 Which crime is that? Presumably you mean an actual criminal felony, not a
 mere civil offence. Under which jurisdiction?

 If piracy is a crime, and not just a civil offence, then surely so is
 libel.

 You've got your OO class hierarchy mixed up and then imposing that on me.

 See
 http://www.nolo.com/legal-encyclopedia/crimes-felonies-misdemeanors-infractions-classification-33814.html

 I did not say or suggest felony.
 Maybe misdemeanor or infarction. Dunno which. IANAL...

The specific terms don't really matter here, but in most
jurisdictions, felony will be a term that unambiguously refers to a
crime against the law, as distinct from what Steven is comparing
against, civil damages.

If I shoot you dead, I have committed murder. This is a crime.

If I put up a sign saying Entrance to your business name over my
own door, next to yours, then I have committed no crime, but you can
sue me in civil court for your loss of business resulting from my
action.

Whether one of them is classed as a felony in some jurisdiction or not
doesn't matter, what matters is that one is simply not a crime.
Violating a license agreement usually is not a crime (and if done in
good faith, is often considered a bug to be fixed, not a suit to be
pressed - but that does NOT apply here), hence the analogies to
criminal action somewhat break down.

That said, though, offering in public to rip someone off is just as
unwise as offering in public to commit a crime.

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


Re: DOS or not? [was Re: How to tell Script to use pythonw.exe ?]

2013-07-04 Thread Chris Angelico
On Fri, Jul 5, 2013 at 8:12 AM, Andrew Berg robotsondr...@gmail.com wrote:
 On 2013.07.04 09:08, Wayne Werner wrote:
 powershell -ExecutionPolicy Bypass -File ...


 \o/

 Microsoft security at it again! (reminds me a bit of just pushing
 Cancel to log into windows 98, I think it was)
 From an MSDN page linked in one of the answers:
 Now, why is

 PowerShell.exe –ExecutionPolicy Bypass –File c:\temp\bad-script.ps1

 not a security bug? Ultimately, if bad code has the ability to run this 
 code, it already has control of the machine.
 http://blogs.msdn.com/b/powershell/archive/2008/09/30/powershell-s-security-guiding-principles.aspx

 If an attacker can run code, he/she already has the capability to well, run 
 code.

Well, the whole point of sandboxing is to allow some code and not
other - look at web browser scripts. You can run your JavaScript code
on someone else's machine without the capability to run arbitrary
code.

What this proves is that PowerShell is not a sandboxing environment.
It has just two states: Trusted and untrusted. Untrusted code may not
run. Trusted code has full access as though the administrator typed
the commands by hand.

Unix has measures to prevent a running process from having full
control over the system, but even there, privilege escalation attacks
(usually involving some application that runs as root) have been
known. Restricting a running binary (as opposed to creating an
interpreted and very slow language) is a distinctly hard problem.

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


Re: Default scope of variables

2013-07-04 Thread Joshua Landau
On 4 July 2013 17:54, Rotwang sg...@hotmail.co.uk wrote:
 53*(63**100 - 1)//62

Or about 10**10**6.255 (so about 1.80M digits long).


For the unicode side (Python 3, in other words) and reusing your math
(ya better hope it's right!), you are talking:

97812*((97812+2020)**100 - 1)/(97812+2020-1)

Or about 10**10**6.699

Which has about 5.00M digits.


Good luck running out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

2013-07-04 Thread Nobody
On Thu, 04 Jul 2013 13:38:09 +0300, Νίκος wrote:

 So you are also suggesting that what gesthostbyaddr() returns is not 
 utf-8 encoded too?

The gethostbyaddr() OS function returns a byte string with no specified
encoding. Python 3 will doubtless try to decode that to a character string
using some (probably unspecified) encoding.

Names obtained from DNS should consist entirely of ASCII characters
(gethostbyname shouldn't attempt to decode internationalised names
which use IDN, it should return the raw data).

Names obtained by other means (e.g. /etc/hosts or Active Directory) could
contain anything, but if you use non-ASCII hostnames you're asking for
trouble.

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


Re: Important features for editors

2013-07-04 Thread Joshua Landau
On 4 July 2013 08:32, cutems93 ms2...@cornell.edu wrote:
 I am researching on editors for my own reference. I found that each of them 
 has some features that other don't, but I am not sure which features are 
 significant/necessary for a GOOD editor. What features do you a good editor 
 should have? Keyboard shortcuts? Extensions?

Let me give you some reasons I really, really like Sublime Text.

* Fast. Like, really fast. I've used Vim -- Sublime Text is faster.
Considering I'm on a middle-end 5-year-old computer (not for long...)
this matters.

* The rendering is gorgeous. There are subtle shadows, there's
perfectly crisp text (the main reason I no longer use terminal
editors, actually), and once you choose the right theme (Nexus and
Phoenix, Tomorrow Night for me) it's just lovely. There's this feature
where it shows you tabs -- but only for the part of the file you're
on. There's, instead of a scrollbar, a little bird's-eye-view of the
whole code on the RHS. This goes on. Visually it is stunning, in a
helpful way. If it had proper terminal-emulation support, I'd replace
my terminal with it. It's just that usable an interface.

* Multiple cursors. This is something that no-one else really
advertises, but it's one of the most used features for me. It's
something you just have to try for a while -- I think it's a bit like
Vim's power-of-Regex but easy for a, you know, human. (I just found
https://github.com/terryma/vim-multiple-cursors).

* Good navigation between and inside of files. A lot of things have
this, so I won't say much more.

* The Command Palette is a dropdown that you do commands from, and
because of the way you search it, it's like a hybrid between vim's
command-based power and something that's actually discoverable and
easy.

* Usable on *really big* files, and has one of the best binary-file
support I know of. I open binary file a little more than I should, not
that I can do much with them.

* Useful extensions, installable at a button-press --
C-PinCR[search for package]CR. Like SublimeREPL. I know
Emacs/Vim will do better at REPLs, but few others will.

* Etc. This goes on.

Looking at Dave Angel's list, Sublime Text pretty-much aces it.

What I don't understand is where he says:

 The main negatives I can see are:
...
 It's available for OS/X, Linux and Windows, with a single purchase
 The eval/demo is not time-limited (currently)

How on earth are those negatives?

He basically only dislikes it because you have to use PayPal, which is
his choice. I can't say I agree with it though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decorator help

2013-07-04 Thread Joshua Landau
On 4 July 2013 06:39, Peter Otten __pete...@web.de wrote:
 Joshua Landau wrote:

 On 3 July 2013 23:19, Joshua Landau joshua.landau...@gmail.com wrote:
 If you don't want to do that, you'd need to use introspection of a
 remarkably hacky sort. If you want that, well, it'll take a mo.

 After some effort I'm pretty confident that the hacky way is impossible.

 Well, technically it's

 func.func_closure[0].cell_contents.__name__

 but of course you cannot know that for the general case.

I didn't want to do something like that as it implies a lot of
knowledge about the function -- which implies that there's no reason
to do it hacky in the first place. I was using
inspect.getclosurevars(func).nonlocals and that coerces to a
dictionary first. It's the correct way of doing things. But you
never know what name the function inside the wrapper is bound to, so I
didn't accept that.

Also, your method has undefined behaviour AFAIK -- the order of
func_closure is compiler-dependant. If you want to do something like
this, I recommend my method (but it doesn't work for the general case
in the slightest):

inspect.getclosurevars(func).nonlocals[func].__name__

If you can't assume the name it's stored in, but you can know the
order of closure variables *then* use Peter's. But again, don't use
either; it's impossible just as I said.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Important features for editors

2013-07-04 Thread Dave Angel

On 07/04/2013 08:38 PM, Joshua Landau wrote:

On 4 July 2013 08:32, cutems93 ms2...@cornell.edu wrote:

I am researching on editors for my own reference. I found that each of them has 
some features that other don't, but I am not sure which features are 
significant/necessary for a GOOD editor. What features do you a good editor 
should have? Keyboard shortcuts? Extensions?


Let me give you some reasons I really, really like Sublime Text.

* Fast. Like, really fast. I've used Vim -- Sublime Text is faster.
Considering I'm on a middle-end 5-year-old computer (not for long...)
this matters.

* The rendering is gorgeous. There are subtle shadows, there's
perfectly crisp text (the main reason I no longer use terminal
editors, actually), and once you choose the right theme (Nexus and
Phoenix, Tomorrow Night for me) it's just lovely. There's this feature
where it shows you tabs -- but only for the part of the file you're
on. There's, instead of a scrollbar, a little bird's-eye-view of the
whole code on the RHS. This goes on. Visually it is stunning, in a
helpful way. If it had proper terminal-emulation support, I'd replace
my terminal with it. It's just that usable an interface.

* Multiple cursors. This is something that no-one else really
advertises, but it's one of the most used features for me. It's
something you just have to try for a while -- I think it's a bit like
Vim's power-of-Regex but easy for a, you know, human. (I just found
https://github.com/terryma/vim-multiple-cursors).

* Good navigation between and inside of files. A lot of things have
this, so I won't say much more.

* The Command Palette is a dropdown that you do commands from, and
because of the way you search it, it's like a hybrid between vim's
command-based power and something that's actually discoverable and
easy.

* Usable on *really big* files, and has one of the best binary-file
support I know of. I open binary file a little more than I should, not
that I can do much with them.

* Useful extensions, installable at a button-press --
C-PinCR[search for package]CR. Like SublimeREPL. I know
Emacs/Vim will do better at REPLs, but few others will.

* Etc. This goes on.

Looking at Dave Angel's list, Sublime Text pretty-much aces it.

What I don't understand is where he says:


The main negatives I can see are:

...

 It's available for OS/X, Linux and Windows, with a single purchase
 The eval/demo is not time-limited (currently)


How on earth are those negatives?



A typo.  I was collecting points and trying to put them in categories, 
but somehow that didn't end up in the right place.



He basically only dislikes it because you have to use PayPal, which is
his choice. I can't say I agree with it though.




--
DaveA

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


Re: Illegal suggestions on python list

2013-07-04 Thread alex23

On 5/07/2013 4:18 AM, feedthetr...@gmx.de wrote:

 Oh, sorry, we forgot, that the US legal system is the only one applicable

 to the internt (and of course to the whole world).

Given that Australian citizens (at least) have been extradited to the
US for piracy crimes that weren't commited on US soil, it's not that
far from the truth, unfortunatley.

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


Re: Default scope of variables

2013-07-04 Thread Steven D'Aprano
On Thu, 04 Jul 2013 17:54:20 +0100, Rotwang wrote:
[...]
 Anyway, none of the calculations that has been given takes into account
 the fact that names can be /less/ than one million characters long. 


Not in *my* code they don't!!!

*wink*


 The
 actual number of non-empty strings of length at most 100 characters,
 that consist only of ascii letters, digits or underscores, and that
 don't start with a digit, is
 
 sum(53*63**i for i in range(100)) == 53*(63**100 - 1)//62


I take my hat of to you sir, or possibly madam. That is truly an inspired 
piece of pedantry.


 It's perhaps worth mentioning that some non-ascii characters are allowed
 in identifiers in Python 3, though I don't know which ones.

PEP 3131 describes the rules:

http://www.python.org/dev/peps/pep-3131/

For example:

py import unicodedata as ud
py for c in 'é極¿μЖᚃ‰⇄∞':
... print(c, ud.name(c), c.isidentifier(), ud.category(c))
...
é LATIN SMALL LETTER E WITH ACUTE True Ll
æ LATIN SMALL LETTER AE True Ll
¥ YEN SIGN False Sc
µ MICRO SIGN True Ll
¿ INVERTED QUESTION MARK False Po
μ GREEK SMALL LETTER MU True Ll
Ж CYRILLIC CAPITAL LETTER ZHE True Lu
ᚃ OGHAM LETTER FEARN True Lo
‰ PER MILLE SIGN False Po
⇄ RIGHTWARDS ARROW OVER LEFTWARDS ARROW False So
∞ INFINITY False Sm



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


Re: Coping with cyclic imports

2013-07-04 Thread Cameron Simpson
On 04Jul2013 16:03, Oscar Benjamin oscar.j.benja...@gmail.com wrote:
| On 4 July 2013 13:48,  kanchan.n.maha...@gmail.com wrote:
|  On Tuesday, April 8, 2008 10:06:46 PM UTC+2, Torsten Bronger wrote:
|  
http://stackoverflow.com/questions/744373/circular-or-cyclic-imports-in-python
| 
| Is there some reason you're responding to a post from 5 years ago?

Is there some reason not to, if no newer solutions are available?

Certainly if someone has new input on an old Python thread, which
is legitimately part of the old thread, I am _glad_ if they reply
to the old post. It pulls the whole prior thread content up the top
for my perusal should it be necessary. If they make a new post I
have to go digging through archives if I need to do that.

Cheers,
-- 
Cameron Simpson c...@zip.com.au
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First attempt at a Python prog (Chess)

2013-07-04 Thread Joshua Landau
Just a minor suggestion:

def display_board(board):
  print '  a   b   c   d   e   f   g   h'
  print '+---+---+---+---+---+---+---+---+'
  for row in range(8):
  for col in range(8):
  piece = board[row * 8 + col]

  if piece_type[piece] == WHITE:
print '| \x1b[31;01m%c\x1b[39;49;00m' % board[row * 8 + col],

  else:
print '| \x1b[34;01m%c\x1b[39;49;00m' % board[row * 8 + col],

  print '|', 8 - row

  print '+---+---+---+---+---+---+---+---+'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How is this evaluated

2013-07-04 Thread Steven D'Aprano
On Thu, 04 Jul 2013 10:20:43 -0700, Arturo B wrote:

 I'm making this exercise: (Python 3.3)
 
 Write a function translate() that will translate a text into
 rövarspråket (Swedish for robber's language). That is, double every
 consonant and place an occurrence of o in between. For example,
 translate(this is fun) should return the string tothohisos isos
 fofunon.
 
 So I tried to solved it, but I couldn't, so I found many answers, but I
 selected this:
 
 def translate(s):
   consonants = 'bcdfghjklmnpqrstvwxz'
   return ''.join(l + 'o' + l if l in consonants else l for l in s)

The part inside the join(...) is called a generator expression.

I do not recommend generator expressions (or list comprehensions) for 
beginners, because they can be confusing until you understand how they 
work. As a beginner, if you have a choice between a one-line piece of 
code that makes no sense to you, and a five-line piece of code that you 
understand, you should choose the one that you understand.


 So I want to question:
 How is the
 
 if 'h' in consonants else 'h' for 'h' in s
 
 part evaluated? (step by step please :P )

That is the wrong question, because you have split the code in the wrong 
places. Your generator expression looks like this:

l + 'o' + l if l in consonants else l for l in s

This is a generator expression of the form:

(x for l in s)

where x will be defined below. This part is easy enough to understand: 
Python will iterate over the string s, extracting one letter at a time l, 
and then evaluate the expression x below.

What is the expression x? It is this part:

(l + 'o' + l if l in consonants else l)

which forms the ternary operator if-clause:

value-if-true if condition-being-tested else value-if-false

If you know C, that's like:

?(condition-being-tested, value-if-true, value-if-false)

The condition being tested is, l in consonants. The value if true is l 
+ 'o' + l. And the value if false is just l.

So putting this all together, we can convert the generator expression 
version to this longer, but more readable, version:

def translate(s):
consonants = 'bcdfghjklmnpqrstvwxz'
collector = []
for l in s:
if l in consonants:
collector.append(l + 'o' + l)
else:
collector.append(l)
return ''.join(collector)



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


  1   2   >