Chardet, file, ... and the Flexible String Representation

2013-09-06 Thread wxjmfauth
Short comment about the "detection" tools from a previous
discussion.

The tools supposed to detect the coding scheme are all
working with a simple logical mathematical rule:

p  ==> q<==>   non q  ==> non p .

Shortly  -- and consequence  --  they do not detect a
coding scheme they only detect "a" possible coding schme.


The Flexible String Representation has conceptually to
face the same problem. It splits "unicode" in chunks and
it has to solve two problems at the same time, the coding
and the handling of multiple "char sets". The problem?
It fails.
"This poor Flexible String Representation does not succeed
to solve the problem it create itsself."

Workaround: add more flags (see PEP 3xx.)

Still thinking "mathematics" (limit). For a given repertoire
of characters one can assume that every char has its own
flag (because of the usage of multiple coding schemes).
Conceptually, one will quickly realize, at the end, that they
will be an equal amount of flags and an amount of characters
and the only valid solution it to work with a unique set of
encoded code points, where every element of this set *is*
its own flag.
Curiously, that's what the utf-* (and btw other coding schemes
in the byte string world) are doing (with plenty of other
advantages).

Already said. An healthy coding scheme can only work with
a unique set of encoded code points. That's why we have to
live today with all these coding schemes.

jmf

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


Re: Importing Definitions

2013-09-06 Thread Azureaus
Thanks for the advice, much appreciated - I didn't realise you could also 
import definitions. I do always read the documentation before posting but 
sometimes I don't know how it's necessarily applicable to my own case sometimes 
- hence the post. I'll avoid using '*' at all costs, I've had the pleasure of 
going through lots of Python code recently not written by myself and I can see 
how that would make it a total nightmare to figure out what was going on.

I think Python is awesome and look forward to actually getting good with it.
Cheers!

On Thursday, 5 September 2013 13:39:37 UTC+1, Azureaus  wrote:
> Hi all,
> 
> Thank you all for your help so far in the group.
> 
> 
> 
> Lets say I have some definitions in a module1.py e.g.
> 
> 
> 
> import sys
> 
> A,B,C,D,E = range(5)
> 
> def method1():
> 
> more code
> 
> end
> 
> 
> 
> Then a second module module2.py where I wish to use these definitions
> 
> import module1.py
> 
> print A
> 
> 
> 
> This will throw an error saying "global name 'A' is not defined."
> 
> 
> 
> Now I know if there was a method I wanted to reference I could do something 
> like this in module2.
> 
> from module1 import method1
> 
> 
> 
> which would mean from that point on I could just reference it as method1 
> rather than module1.method1, is there such a way I could do this with 
> definitions??
> 
> 
> 
> Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Importing Definitions

2013-09-06 Thread Oscar Benjamin
On 5 September 2013 19:06, Skip Montanaro  wrote:
>>> You can! Any name will work, functions aren't special.
>>>
>>> from module1 import method1, A, B, C, D, E
>>
>> Better practice is to use:
>>
>> import module1
>> print module1.A
>> print module2.B
>>
>> and so forth since that makes it far more clear what you are doing and
>> where they come from. But it's not compulsory.
>
> Maybe I'm imagining things, but I think it's pretty common to see some
> big-ass modules imported using "from module import *".  While people
> may think that's expedient, I think it can often be the source of
> subtle bugs.

It is common in scientific programming e.g. 'from numpy import *' and
so on. And actually I think that it is a reasonable thing to do in
cases where:
1) You're writing a single smallish module/script.
2) The imported module is well-known and anyone who doesn't know it
won't understand your code anyway.
3) You're only doing one star-import.
4) You're using a lot of symbols from that import in lots of places in
your code.

Consider for example, this script:

#!/usr/bin/env python

import numpy
import matplotlib.pyplot

k = 1
f = 10
x = numpy.arange(0, 3, 0.01)
y = numpy.exp(k * x) * numpy.sin(2 * numpy.pi * x)

matplotlib.pyplot.plot(x, y)
matplotlib.pyplot.show()

I write a lot of scripts that look roughly like that except they're
usually quite a bit bigger. Written as above, the word numpy would
appear dozens of times in a single script. Because of this it's
commonplace to abbreviate the module names on import e.g.:

#!/usr/bin/env python

import numpy as np
import matplotlib.pyplot as plt

k = 1
f = 10
x = np.arange(0, 3, 0.01)
y = np.exp(k * x) * np.sin(2 * np.pi * x)

plt.plot(x, y)
plt.show()

But still in situations where you have to write 'np.' 3 or more times
on a line, it just becomes a distraction in your code. Of course you
can just import the names you want e.g.:

#!/usr/bin/env python

from numpy import arange, exp, sin, pi
from matplotlib.pyplot import plot, show

k = 1
f = 10
x = arange(0, 3, 0.01)
y = exp(k * x) * sin(2 * pi * x)

plot(x, y)
show()

But this just gets annoying. In practice I'll probably end up
importing 20 or so names. When writing a script like this I probably
tweak and rerun it continuously and so when I decide that actually I
meant cos not sin then I run it and get:

$ ./tmp3.py
Traceback (most recent call last):
  File "./tmp3.py", line 9, in 
y = exp(k * x) * cos(2 * pi * x)
NameError: name 'cos' is not defined

And then I have to go back and edit the import line. This kind of
thing just wastes a bit of time while I'm working. So the matplotlib
folks created a special module called "pylab" that brings together the
symbols from numpy and matplotlib and is specifically designed so that
you can star-import it when writing this kind of code interactively or
in a script:

#!/usr/bin/env python

from pylab import *

k = 1
f = 10
x = arange(0, 3, 0.01)
y = exp(k * x) * sin(2 * pi * x)

plot(x, y)
show()

The pylab star-import brings a *huge* number of symbols into the
current namespace:

$ python -c 'import pylab; print(len(pylab.__dict__))'
933

However, it's very common that this set of symbols comprises
everything that a script needs. Personally I don't think there's
anything wrong with using that in a script (with the caveats I
mentioned above). A similar case is in a script that uses sympy (I
wouldn't do it with pylab and sympy together though). In either case I
would tend to think that I'm essentially using an augmentation of
builtins. Just as you need to know roughly what's in builtins to
understand ordinary Python code, you need to know what's in pylab or
sympy to understand this script.


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


Re: PEP8 79 char max

2013-09-06 Thread Skip Montanaro
> Well, what I interpret as the PEP8 79 is chars visible minus the '\n' or 
> '\r\n'(which would be 2; 81) line enders.

You young un's. Always makin' stuff up... :-)

In these days of fancy single-user PCs with sophisticated window
systems, people tend to forget that BITD there was a thriving market
for serially-connected terminals (most only had 80 columns and 24
rows) connected to timesharing machines of various kinds (DEC VAX and
PDP-11 machines were extremely common in the Unix world). Many (some?
most? all?) of those terminals had a "feature" where if a character
was displayed in column 80, the cursor would automatically wrap around
and blink mindlessly in column 1 of the next row. That was even more
unpleasant behavior if you happened to enter text in the last column
of the last row, as then your cursor would blink in row 1, column 1. I
think there is a termcap code that specifies whether or not a given
terminal exhibits this behavior.

Hence 79.

/etc/termcap on my OpenSuSE system has over 1600 entries, most for
terminals which were resigned to the junk heap decades ago. Today, we
can probably just get by with entries for a couple xterm or ansi
variants.

And thank goodness for SIGWINCH. :-)

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


Re: file handling issues

2013-09-06 Thread leo . carnovale
On Friday, 6 September 2013 20:20:02 UTC+10, leo.ca...@gmail.com  wrote:
> I am making this little game and I am trying to make some sort of script that 
> does the following:
> 
> >Checks to see if a file exists
> 
>  >If it does, check the numbers in it
> 
>  >If it doesn't, make one and fill it with some numbers
> 
> >Sorts out if the numbers in the file are in the right format
> 
>  >If they are, then store them
> 
>  >If not, remake it again
> 
> >THEN, check if there is a pass.
> 
>  >If there is, check if it fits the key and go on if so
> 
>  >If not, ask for a new one, check it, go on if its correct.
> 
> 
> 
> Every time I run it, it says the key is 0!?
> 
> I can not for the life of me figure out what it is doing.
> 
> 
> 
> The code:
> 
> 
> 
> 
> 
> Thanks
> 
> 
> 
> Leo

Probably should also mention this,
The KEY is what the user is presented with, and to use the program, they must 
enter a corresponding PASS which is created with a special manipulator that I 
made.
-- 
https://mail.python.org/mailman/listinfo/python-list


file handling issues

2013-09-06 Thread leo . carnovale
I am making this little game and I am trying to make some sort of script that 
does the following:
>Checks to see if a file exists
 >If it does, check the numbers in it
 >If it doesn't, make one and fill it with some numbers
>Sorts out if the numbers in the file are in the right format
 >If they are, then store them
 >If not, remake it again
>THEN, check if there is a pass.
 >If there is, check if it fits the key and go on if so
 >If not, ask for a new one, check it, go on if its correct.

Every time I run it, it says the key is 0!?
I can not for the life of me figure out what it is doing.

The code:


Thanks

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


Re: PEP8 79 char max

2013-09-06 Thread Tim Chase
On 2013-09-06 05:09, Skip Montanaro wrote:
> And thank goodness for SIGWINCH. :-)

BEDEVERE: How do you know she is a SIGWINCH?

VILLAGER: She looks like one.

CROWD: Right! Yeah! Yeah!


:-)

I'm just glad it's no longer 40-chars-per-column and purely
upper-case like the Apple ][+ on which I cut my programming teeth.

-tkc




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


Re: PEP8 79 char max

2013-09-06 Thread Tim Delaney
On 6 September 2013 20:35, Tim Chase  wrote:

> On 2013-09-06 05:09, Skip Montanaro wrote:
> > And thank goodness for SIGWINCH. :-)
>
> BEDEVERE: How do you know she is a SIGWINCH?
>
> VILLAGER: She looks like one.
>
> CROWD: Right! Yeah! Yeah!
>
>
> :-)
>
> I'm just glad it's no longer 40-chars-per-column and purely
> upper-case like the Apple ][+ on which I cut my programming teeth.
>

Couldn't you switch the ][+ into high-res mode? You could with the IIe.
Made programming in DOS 3.3 BASIC so much nicer.

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


Re: Chardet, file, ... and the Flexible String Representation

2013-09-06 Thread Steven D'Aprano
On Fri, 06 Sep 2013 02:11:56 -0700, wxjmfauth wrote:

> Short comment about the "detection" tools from a previous discussion.
> 
> The tools supposed to detect the coding scheme are all working with a
> simple logical mathematical rule:
> 
> p  ==> q<==>   non q  ==> non p .

Incorrect.

chardet does a statistical analysis of the bytes, and tries to guess what 
language they are likely to come from. The algorithm is described here:

https://github.com/erikrose/chardet/blob/master/docs/how-it-works.html

(although that's rather inconvenient to read), and here:

http://www-archive.mozilla.org/projects/intl/
UniversalCharsetDetection.html


chardet is a Python port of the Mozilla charset guesser, so they use the 
same algorithm.


> Shortly  -- and consequence  --  they do not detect a coding scheme they
> only detect "a" possible coding schme.

That at least is correct.


> The Flexible String Representation has conceptually to face the same
> problem. 

No it doesn't.


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


Re: Chardet, file, ... and the Flexible String Representation

2013-09-06 Thread Antoon Pardon
Op 06-09-13 11:11, wxjmfa...@gmail.com schreef:

> 
> The Flexible String Representation has conceptually to
> face the same problem. It splits "unicode" in chunks and
> it has to solve two problems at the same time, the coding
> and the handling of multiple "char sets". The problem?

Not true. The FSR always uses the same coding. An "A" is
always coded as 65.

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


Re: Chardet, file, ... and the Flexible String Representation

2013-09-06 Thread Ned Batchelder

On 9/6/13 5:11 AM, wxjmfa...@gmail.com wrote:

The Flexible String Representation has conceptually to
face the same problem. It splits "unicode" in chunks and
it has to solve two problems at the same time, the coding
and the handling of multiple "char sets". The problem?
It fails.


Just once, please say *how* it fails.  :(

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


Re: Python Debugger tool

2013-09-06 Thread Fabio Zadrozny
On Fri, Sep 6, 2013 at 3:14 AM, chandan kumar wrote:

> Hi
>
> Is any one aware of  free ipython debugger tool.How good is this tool for
> a beginner to use like ,placing breakpoints,checking variables ,call stack
> (function flow) etc.I don't like to use python PDB .
>  I have heard about wingware ,pycharm  which are licensed versions.Used
> wingware trail version and felt pretty good tool for beginners.
>
> Please let know your views on ipython.Let me know about any python free
> debugger tools
>

Just a note: the debugger in PyCharm is actually a fork of the PyDev
debugger, so, using PyDev (which is Open Source) may be an option if you'd
like something more visual than the IPython debugger (see:
http://pydev.org/manual_adv_debugger.html for the debugger and
http://pydev.org/manual_101_root.html for installing/configuring PyDev
initially).

Cheers,

Fabio


>
>
> Best Regards,
> Chandan
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP8 79 char max

2013-09-06 Thread Metallicow

RailRoadTieWidth = 79.1234567890

>>> 79 = 'Width Of A Horse"s Ass'
  File "", line 1
SyntaxError: can't assign to literal

>>>RailRoadTieWidth.attribute
("American", "Steam")

>>>79.attribute = ("Roman", "Chariot")
  File "", line 1
79.attribute = ("Roman", "Chariot")
   ^
SyntaxError: invalid syntax

Excuse me if this may be improper in you native language, butt...
If the interpreter didn't have a sense of humor, I believe most people wouldn't 
use python.

Most often it will return an answer, that is concise, but with a bit of flair.

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


Re: PEP8 79 char max

2013-09-06 Thread Tim Chase
On 2013-09-06 20:47, Tim Delaney wrote:
> On 6 September 2013 20:35, Tim Chase wrote:
> > I'm just glad it's no longer 40-chars-per-column and purely
> > upper-case like the Apple ][+ on which I cut my programming teeth.
> 
> Couldn't you switch the ][+ into high-res mode? You could with the
> IIe. Made programming in DOS 3.3 BASIC so much nicer.

There was an 80-column add-on card that also supported lower-case
(though, IIRC, you also had to do a hardware hack to wire the 
key to the joystick button to get it to be recognized in certain
cases).  The IIe was a far better machine, having the 80-column card
built in.  PR#3 :-)

I'm also glad Python doesn't require prefixing lines with
line-numbers for GOTO/GOSUB purposes, then requiring external
the line-renumbering utilities that AppleSoft BASIC required :-S

-tkc



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


Re: PEP8 79 char max

2013-09-06 Thread Neil Cerutti
On 2013-09-06, Tim Chase  wrote:
> On 2013-09-06 20:47, Tim Delaney wrote:
>> On 6 September 2013 20:35, Tim Chase wrote:
>> > I'm just glad it's no longer 40-chars-per-column and purely
>> > upper-case like the Apple ][+ on which I cut my programming
>> > teeth.
>> 
>> Couldn't you switch the ][+ into high-res mode? You could with
>> the IIe. Made programming in DOS 3.3 BASIC so much nicer.
>
> There was an 80-column add-on card that also supported
> lower-case (though, IIRC, you also had to do a hardware hack to
> wire the  key to the joystick button to get it to be
> recognized in certain cases).  The IIe was a far better
> machine, having the 80-column card built in.  PR#3 :-)
>
> I'm also glad Python doesn't require prefixing lines with
> line-numbers for GOTO/GOSUB purposes, then requiring external
> the line-renumbering utilities that AppleSoft BASIC required
> :-S

Though its graphics and sound were far inferior, as a C64 user I
was really jealous of the speed of the built-in Apple disk
drives. The only programming I did on them was typing in some of
the programs from "Compute!", back before it converted format to
C64 only. Anybody care for a game of Laserchess?

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


Re: How to split with "\" character, and licence copyleft mirror of ©

2013-09-06 Thread random832
On Thu, Sep 5, 2013, at 23:33, Tim Roberts wrote:
> random...@fastmail.us wrote:
> >
> >Of course, in 99% of situations where you can use a windows pathname in
> >Python, you are free to use it with a forward slash instead of a
> >backslash.
> 
> This is actually worth repeating, because it's not well known.
> 
> ALL Windows APIs handle forward and backward slashes interchangably.  It
> is only the command interpreter that requires the backslash.

Technically, that's not strictly true. There are certain strings you can
open that will only work with backslashes, relating to device paths
and/or the magic \\?\ prefix that removes the PATH_MAX limit
(CreateFileW only). That was what I meant by 99%.

And many situations in the command interpreter that require a backslash
can be used with forward slash by surrounding the string in quotes,
which you need to do anyway when you have an arbitrary string that may
contain spaces.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP8 79 char max

2013-09-06 Thread Metallicow
On Thursday, September 5, 2013 11:01:31 PM UTC-5, Steven D'Aprano wrote:
> On Thu, 05 Sep 2013 19:59:34 -0700, Metallicow wrote:
> > PEP8 needs a bit of revision anyway, In my opinion... According to
> > real-world standards for equipment/devices. linking to a table/list of
> > affected devices/minNumbers should be the norm. or
> 
> I don't believe you have thought this through, or in any detail. The 
> first problem is, what "real-world standards" are you talking about? What 
> sort of devices are you referring to? How is this supposed to work in 
> practice? If I write a Python module, which device am I supposed to pick?

http://en.wikipedia.org/wiki/Revision
Why even define a number?
I causes people to argue about it. It is a variable.
I meant a "Reference" Table of equipment/devices.
Most Auto shop have a "Cross-Reference book". Also Johnny Cash built a vehicle 
from 30 years or so different years parts(or I know people who do/can).
Reference PEP8 standard to: A Technical manual per say.
If not make it simple. A multiple of 10, 80 being the closest int and also 
errors on 79 devices. Which then said device should be added to the reference 
manual. Or 70.
Also the pro/cons of this argument should be added to a "Quick-Reference".

Sorry if my opinion was not clear, the first time I posted. As I have been 
answered before, you CANNOT edit posts here. But you could with python... 

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


Re: to be pythonic: should caller or callee log?

2013-09-06 Thread Gildor Oronar

El 04/09/13 20:14, Xaxa Urtiz escribió:

and what about something like that :


class AbsctractAccount():
  def transaction(self, amount, target):
  logging.info("Start transaction of %s to %s" % (amount, target))
  self.DoTransaction(amount,target)

  def DoTransaction(self,amount,target):
  pass # or raise notimplemented or do not implement this methods in 
the abstract class
  ...

class DebitAccount(AbstractAccount):
  def DoTransaction(self, amount, target):
  ...

class SomeOtherAccount(...)
  
like that you only have to write the logging function once.


Thanks for the hint! This also work well, and has the advantage of being 
specific to this function -- I did use decorator as Ethan suggested, 
which works for most of the case, but there is function (other than 
transaction) needs specialized logging because the function doesn't 
return anything but changes a class variable -- using a special 
decorator for just one function is over-generalizing, and your method 
kicks in.


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


Re: how to trouble shoot - RuntimeError: Open Failed

2013-09-06 Thread Steven D'Aprano
On Fri, 06 Sep 2013 08:00:13 -0700, stas poritskiy wrote:

> hey guys,
> I am working on application. App is processing a list of files in
> folders. Folders act as a NEW-LOOP. so if all files in one folder had
> been worked on, file is then saved and next folder is picked up. it
> works fine only if i have a SINGLE folder, however, when another folder
> is there, i get this RuntimeError: Open Failed. I checked if those could
> be the files by leaving only single (another folder), however all was
> fine. Questions - How can i trouble shoot what is causing the problem? i
> don't know where to begin.

You should ALWAYS begin with the entire traceback, not just the last 
line. Everything starting with:

Traceback (most recent call last):


and ending with the last line, which in your case will be something like 
"RuntimeError: Open failed". The most important part is that the 
traceback will actually show you the line that fails.

Secondly, whose code is this? I assume it is code you have written. In 
that case, do you have something like this in your code?

try:
blah blah blah  # whatever, doesn't matter what this is
except:
raise RuntimeError("Open failed")


If so, take it out immediately! All you are doing is catching a *useful* 
exception that Python generates, and replacing it with an utterly useless 
exception that does nothing but hide the true cause of the problem and 
make debugging much more difficult.


That will do to start. If you still need help, please copy and paste the 
entire traceback. Also, demonstrating a *minimal* amount of code that 
causes this error will help. Although this is written for Java 
programmers, the same principles apply to Python code too:

http://sscce.org/


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


how to trouble shoot - RuntimeError: Open Failed

2013-09-06 Thread stas poritskiy
hey guys,
I am working on application. App is processing a list of files in folders.
Folders act as a NEW-LOOP. so if all files in one folder had been worked on, 
file is then saved and next folder is picked up.
it works fine only if i have a SINGLE folder, however, when another folder is 
there, i get this RuntimeError: Open Failed.
I checked if those could be the files by leaving only single (another folder), 
however all was fine.
Questions - How can i trouble shoot what is causing the problem? i don't know 
where to begin.

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


Re: PEP8 79 char max

2013-09-06 Thread Metallicow
Google(will) Search This Message:
Industry Standards, PEP8, Whitespace, Print, Printing, Opinion'
I could add more... For example: Pantone color wheel.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: file handling issues

2013-09-06 Thread Piet van Oostrum
leo.carnov...@gmail.com writes:

> I am making this little game and I am trying to make some sort of script that 
> does the following:
>>Checks to see if a file exists
>  >If it does, check the numbers in it
>  >If it doesn't, make one and fill it with some numbers
>>Sorts out if the numbers in the file are in the right format
>  >If they are, then store them
>  >If not, remake it again
>>THEN, check if there is a pass.
>  >If there is, check if it fits the key and go on if so
>  >If not, ask for a new one, check it, go on if its correct.
>
> Every time I run it, it says the key is 0!?
> I can not for the life of me figure out what it is doing.
>
> The code:
> 
>

What a mess is that code. First that messing around with the key is
crazy. You probably want to do some crypto on it, but why don't you just
use some standard crypto algorithm?

The you have defined T as True and F as False, but sometimes you use T
and sometimes True, and as far as I can see you never use F. Just stay
with True and false as it makes the code more readable.

Once you use "with open('Key')", all other case you use
f = open('Key',...)
f.read() or f.write()
f.close()

Be consistenst and use always "with open..."

There are at least three palces where you write a key to the file. Make
a function for this; it makes your code more structured.

And please, put spaces aroud the = signs.

Now the real problem:

if newpas:
f=open("Key","w")
print("No pass found!")
print("Your wonderful key is: ",int(keys[0]))
pasw=input("What is your pass?   : ")
elif newkey:
f=open("Key","w")

Here you open the file for writing but you never write anything to it.
This makes the file empty. And apparently you do not check this the next
time you open it. If you would have used a function to write a key to
the file, this probably would not have occurred.

if mess_with(keys[0])==pasw:
hesin=1
print("Your in!")
f=open("Key","w")

Here you open the file again with the same variable. This causes the old
value to be lost and the file probably to be closed. Just messy.

print("writing %s" % str(keys[0])+pasw)
f.write(str(keys[0])+pasw)
f.close()
else:
hesin=0

And how are people supposed to guess an 8 character password? Are they
supposed to do that weird calculation on their calculators or some such?

-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Confessions of a terrible programmer

2013-09-06 Thread Joel Goldstick
On Fri, Sep 6, 2013 at 12:56 PM, Steven D'Aprano
 wrote:
> Not specifically about Python, but still relevant:
>
> http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible-programmer.html
>
>
>
>
>
> --
> Steven
> --
> https://mail.python.org/mailman/listinfo/python-list

Pardon me, but I completely don't get this article.  Let me in on what
is supposed to be the joke please!


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


Re: Chardet, file, ... and the Flexible String Representation

2013-09-06 Thread random832
On Fri, Sep 6, 2013, at 11:46, Piet van Oostrum wrote:
> The FSR does not split unicode in chuncks. It does not create problems
> and therefore it doesn't have to solve this. 
> 
> The FSR simply stores a Unicode string as an array[*] of ints (the
> Unicode code points of the characters of the string. That's it. Then it
> uses a memory-efficient way to store this array of ints. But that has
> nothing to do with character sets. The same principle could be used for
> any array of ints.

I think the source of the confusion is that it is described in terms of
UCS-2 and Latin-1, which people often think of (especially latin-1) as
different encodings rather than merely storing code points in a narrower
type.



Incidentally, how does all this interact with ctypes unicode_buffers,
which slice as strings and must be UTF-16 on windows? This was fine
pre-FSR when unicode objects were UTF-16, but I'm not sure how it would
work now.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to trouble shoot - RuntimeError: Open Failed

2013-09-06 Thread stas poritskiy
The code in development is mine, and i am using the API provided by a main 
developer.

At the moment, i am not using any try/except functionality. 

here is the full Exception output:
[CODE]
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\32bit\lib\lib-tk\Tkinter.py", line 1470, in __call__
return self.func(*args)
  File "E:\sporitskiy\HON\Project\scene7\s7operator\gui.py", line 59, in 

cmd1 = lambda: vntProcessor.colData(folders.path, folders.subFolders)
  File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 184, 
in colData
setVars()
  File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 79, 
in __call__
self.batchFiles()
  File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 55, 
in batchFiles
self.vntConnect.createVNTobjects(self.vntObjMgroup.keyList, 
self.vntLtoF.keyValList, self.vntObjFile.keyList, myPath)
  File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 113, 
in createVNTobjects
self.createImage(groupName, layerName, fileName, imagePath, self.vntGroups)
  File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 137, 
in createImage
img = open_image(imageFile)
  File "", line 2, in open_image
  File "C:\Python27\32bit\lib\site-packages\s7vampy\arg_validator.py", line 
213, in __call__
return func(*args, **keywords)
  File "C:\Python27\32bit\lib\site-packages\s7vampy\image.py", line 181, in 
open_image
return Image(_S7VAM_IMAGE.Open(filename))
RuntimeError: Open Failed: 
'C:/Users/sporitskiy/Desktop/Practice/HIWM2MSB/hiwm2mpa_upholstery_esq_leather_ro_12_0001.tif'

[/CODE]

-- Just a few words on what this all does --

Structure: 3 modules 
Module 1 - dataPreparation.py -responsible for string processing - made of 
several classes and methods that receive PATH to directory, collect all files 
in a LIST, after that for each file based on type of file name it sorts it out 
to appropriate categories that can be accessed through class instances.

Module 2 - gui.py - Responsible for GUI. It crates a simple GUi-layout that 
offer BROWSE button (to get the PATH), QUIT button to exit application, LISTBOX 
that lists subfolders from the PATH, and BATCH button that must execute the 
main processor.

Module 3 - vntProcessor.py - Responsible for processing of collected data. This 
module is based of an API of another application. It receives the values from 
the BATCH-button and invokes specific methods based on sorting that was 
performed using MODULE 1.

My approach:

i created an instance of GUI and call it to start interface ( have a window 
open) in the interface, i browse for specific folder, so my PATH variable is 
set. my list box is populated with subfolders.(using Tkinter for gui)

my next step should be to press the BATCH folder and forward all of the values 
(PATH and ARRAY of SUBFOLDERS) to my Module 3 (processor).
and as soon as my script tries to open NEXT FOLDER is when i get this 
RuntimeError, but if i leave the same folder by itself - everything is fine.

If by looking at the Exception Log i posted, you could tell me what portion of 
the code i should show here - it would be very helpful. thanks!

On Friday, September 6, 2013 10:39:04 AM UTC-5, Neil Cerutti wrote:
> On 2013-09-06, stas poritskiy  wrote:
> 
> > I am working on application. App is processing a list of files
> 
> > in folders. Folders act as a NEW-LOOP. so if all files in one
> 
> > folder had been worked on, file is then saved and next folder
> 
> > is picked up. it works fine only if i have a SINGLE folder,
> 
> > however, when another folder is there, i get this RuntimeError:
> 
> > Open Failed. I checked if those could be the files by leaving
> 
> > only single (another folder), however all was fine. Questions -
> 
> > How can i trouble shoot what is causing the problem? i don't
> 
> > know where to begin.
> 
> 
> 
> We can help better if you show some of your code; a minimal
> 
> cut-down version that exhibits the error is ideal.
> 
> 
> 
> Are you literally getting a RuntimeError? That would be weird.
> 
> 
> 
> -- 
> 
> Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing / threading confusion

2013-09-06 Thread Paul Pittlerson
Ok here is the fixed and shortened version of my script:

#!/usr/bin/python

from multiprocessing import Process, Queue, current_process
from threading import Thread
from time import sleep

class Worker():
def __init__(self, Que):
self._pid = current_process().pid
self.que = Que
self.que.put('started worker %s' % self._pid)

for n in range(5):
self.que.put('%s tick %d' % (self._pid, n))
# do some work
sleep(0.01)

self.que.put('%s has exited' % self._pid) 

class Debugger(Thread):
def __init__(self, q):
super(Debugger, self).__init__()
self.q = q

def run(self):
while True:

sleep(0.1)

if not self.q.empty():
print self.q.get()

else:
break
#

if __name__ == '__main__':

debug_q = Queue()
debug = Debugger(debug_q)
debug.start()

for i in range(5):

d = Process(target=Worker, args=(debug_q,))
d.start()

This works great on linux, but does not run on windows (7). The behavior was: I 
opened it with double clicking and so a window appeared and disappeared (no 
text) then I opened it with IDLE and ran it there, where it worked a couple 
times. Then reopened it with IDLE and this time it did not work at all. After 
that the script did not run either through IDLE or opening directly.

What may be the reason it works on linux, but seems buggy on windows?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Confessions of a terrible programmer

2013-09-06 Thread Walter Hurry
On Fri, 06 Sep 2013 13:17:20 -0400, Joel Goldstick wrote:

> On Fri, Sep 6, 2013 at 12:56 PM, Steven D'Aprano
>  wrote:
>> Not specifically about Python, but still relevant:
>>
>> http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible-
programmer.html
> 
> Pardon me, but I completely don't get this article.  Let me in on what
> is supposed to be the joke please!

No joke. Defensive programming is the only way to go if one is writing a 
serious system, whatever the language.

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


Re: how to trouble shoot - RuntimeError: Open Failed

2013-09-06 Thread Terry Reedy

On 9/6/2013 1:05 PM, stas poritskiy wrote:

The code in development is mine, and i am using the API provided by a main 
developer.

At the moment, i am not using any try/except functionality.

here is the full Exception output:
[CODE]
Exception in Tkinter callback
Traceback (most recent call last):
   File "C:\Python27\32bit\lib\lib-tk\Tkinter.py", line 1470, in __call__
 return self.func(*args)
   File "E:\sporitskiy\HON\Project\scene7\s7operator\gui.py", line 59, in 

 cmd1 = lambda: vntProcessor.colData(folders.path, folders.subFolders)
   File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
184, in colData
 setVars()
   File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 79, 
in __call__
 self.batchFiles()
   File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 55, 
in batchFiles
 self.vntConnect.createVNTobjects(self.vntObjMgroup.keyList, 
self.vntLtoF.keyValList, self.vntObjFile.keyList, myPath)
   File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
113, in createVNTobjects
 self.createImage(groupName, layerName, fileName, imagePath, self.vntGroups)
   File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
137, in createImage
 img = open_image(imageFile)
   File "", line 2, in open_image
   File "C:\Python27\32bit\lib\site-packages\s7vampy\arg_validator.py", line 
213, in __call__
 return func(*args, **keywords)
   File "C:\Python27\32bit\lib\site-packages\s7vampy\image.py", line 181, in 
open_image
 return Image(_S7VAM_IMAGE.Open(filename))
RuntimeError: Open Failed: 
'C:/Users/sporitskiy/Desktop/Practice/HIWM2MSB/hiwm2mpa_upholstery_esq_leather_ro_12_0001.tif'


We were confused because the failed open should be an IOError. If Image 
is indeed converting such to RuntimeError, it should not. It should just 
let the original error bubble up. It is possibly tossing information in 
the process. The first thing I would do is to look at the code around 
that line in image.py and remove the exception replacement if there is one.


--
Terry Jan Reedy

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


Re: Chardet, file, ... and the Flexible String Representation

2013-09-06 Thread Piet van Oostrum
wxjmfa...@gmail.com writes:

> The Flexible String Representation has conceptually to
> face the same problem. It splits "unicode" in chunks and
> it has to solve two problems at the same time, the coding
> and the handling of multiple "char sets". The problem?
> It fails.
> "This poor Flexible String Representation does not succeed
> to solve the problem it create itsself."

The FSR does not split unicode in chuncks. It does not create problems and 
therefore it doesn't have to solve this. 

The FSR simply stores a Unicode string as an array[*] of ints (the Unicode code 
points of the characters of the string. That's it. Then it uses a 
memory-efficient way to store this array of ints. But that has nothing to do 
with character sets. The same principle could be used for any array of ints.

So you are seeking problems where there are none. And you would have a lot more 
peace of mind if you stopped doing this.

[*] array in the C sense.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Confessions of a terrible programmer

2013-09-06 Thread Terry Reedy

On 9/6/2013 12:56 PM, Steven D'Aprano wrote:

Not specifically about Python, but still relevant:


to what?


http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible-programmer.html


I think link posts should have at least a sentence summarizing the 
content of the linked page so I would have some idea of whether it is 
worth me clicking it.


--
Terry Jan Reedy

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


Re: Chardet, file, ... and the Flexible String Representation

2013-09-06 Thread Chris Angelico
On Sat, Sep 7, 2013 at 2:59 AM,   wrote:
> Incidentally, how does all this interact with ctypes unicode_buffers,
> which slice as strings and must be UTF-16 on windows? This was fine
> pre-FSR when unicode objects were UTF-16, but I'm not sure how it would
> work now.

That would be pre-FSR *with a Narrow build*, which was the default on
Windows but not everywhere. But I don't know or use ctypes, so an
answer to your actual question will have to come from someone else.

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


Re: Multiprocessing / threading confusion

2013-09-06 Thread Skip Montanaro
On Fri, Sep 6, 2013 at 1:27 PM, Paul Pittlerson  wrote:
> Ok here is the fixed and shortened version of my script:

Before going any further, I think you need to return to marduk's
response and consider if you really and truly need both threads and
fork (via multiprocessing).

http://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them

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


Confessions of a terrible programmer

2013-09-06 Thread Steven D'Aprano
Not specifically about Python, but still relevant:

http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible-programmer.html





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


Re: Confessions of a terrible programmer

2013-09-06 Thread Skip Montanaro
> Pardon me, but I completely don't get this article.  Let me in on what
> is supposed to be the joke please!

I don't really think there's a joke. I think the author is saying in a
somewhat sly way is that often, the difference between a terrible
programmer and a great programmer is the discipline applied to the
task, and intelligent use of the tools at hand. Catch as many errors
as you can as early as possible (before other people see your original
stabs at a solution) and when your code is set loose in the wild you
will seem like a great programmer. Little do your colleagues know that
your tools protect them from your terrible programming.

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


Re: how to trouble shoot - RuntimeError: Open Failed

2013-09-06 Thread stas poritskiy
Guys, as i was writing a very detailed message with code samples, following the 
guide that Steven linked, i found the problem. a pretty lame one, actually.

in my class that was processing the images, i created an object instance, via 
__INIT__ , self.data = attributes()
but i was iterating through list of folders, so object was filled with the 
correct data, but it was never re-initialized for the new one.

i move my objects into a function, and called the function on each loop-start, 
so objects are re-created and re-filled with the data.


Terry, yeah, your confusion was right, and pointing out that i was supposed to 
get IOError. that lead me to inspect code again and again :)

anyways, thanks and sorry for the mess )





On Friday, September 6, 2013 1:49:57 PM UTC-5, Terry Reedy wrote:
> On 9/6/2013 1:05 PM, stas poritskiy wrote:
> 
> > The code in development is mine, and i am using the API provided by a main 
> > developer.
> 
> >
> 
> > At the moment, i am not using any try/except functionality.
> 
> >
> 
> > here is the full Exception output:
> 
> > [CODE]
> 
> > Exception in Tkinter callback
> 
> > Traceback (most recent call last):
> 
> >File "C:\Python27\32bit\lib\lib-tk\Tkinter.py", line 1470, in __call__
> 
> >  return self.func(*args)
> 
> >File "E:\sporitskiy\HON\Project\scene7\s7operator\gui.py", line 59, in 
> > 
> 
> >  cmd1 = lambda: vntProcessor.colData(folders.path, folders.subFolders)
> 
> >File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
> > 184, in colData
> 
> >  setVars()
> 
> >File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
> > 79, in __call__
> 
> >  self.batchFiles()
> 
> >File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
> > 55, in batchFiles
> 
> >  self.vntConnect.createVNTobjects(self.vntObjMgroup.keyList, 
> > self.vntLtoF.keyValList, self.vntObjFile.keyList, myPath)
> 
> >File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
> > 113, in createVNTobjects
> 
> >  self.createImage(groupName, layerName, fileName, imagePath, 
> > self.vntGroups)
> 
> >File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
> > 137, in createImage
> 
> >  img = open_image(imageFile)
> 
> >File "", line 2, in open_image
> 
> >File "C:\Python27\32bit\lib\site-packages\s7vampy\arg_validator.py", 
> > line 213, in __call__
> 
> >  return func(*args, **keywords)
> 
> >File "C:\Python27\32bit\lib\site-packages\s7vampy\image.py", line 181, 
> > in open_image
> 
> >  return Image(_S7VAM_IMAGE.Open(filename))
> 
> > RuntimeError: Open Failed: 
> > 'C:/Users/sporitskiy/Desktop/Practice/HIWM2MSB/hiwm2mpa_upholstery_esq_leather_ro_12_0001.tif'
> 
> 
> 
> We were confused because the failed open should be an IOError. If Image 
> 
> is indeed converting such to RuntimeError, it should not. It should just 
> 
> let the original error bubble up. It is possibly tossing information in 
> 
> the process. The first thing I would do is to look at the code around 
> 
> that line in image.py and remove the exception replacement if there is one.
> 
> 
> 
> -- 
> 
> Terry Jan Reedy
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Chardet, file, ... and the Flexible String Representation

2013-09-06 Thread Chris Angelico
On Sat, Sep 7, 2013 at 1:46 AM, Piet van Oostrum  wrote:
> The FSR simply stores a Unicode string as an array[*] of ints (the Unicode 
> code points of the characters of the string. That's it. Then it uses a 
> memory-efficient way to store this array of ints. But that has nothing to do 
> with character sets. The same principle could be used for any array of ints.

Python does, in fact, store integers in different-sized blocks of
memory according to size - though not for anything smaller than
32-bit.

>>> sys.getsizeof(100)
14
>>> sys.getsizeof(10)
28

So why this is suddenly a bad thing for characters is a mystery none
but he can comprehend.

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


Re: how to trouble shoot - RuntimeError: Open Failed

2013-09-06 Thread Neil Cerutti
On 2013-09-06, stas poritskiy  wrote:
> I am working on application. App is processing a list of files
> in folders. Folders act as a NEW-LOOP. so if all files in one
> folder had been worked on, file is then saved and next folder
> is picked up. it works fine only if i have a SINGLE folder,
> however, when another folder is there, i get this RuntimeError:
> Open Failed. I checked if those could be the files by leaving
> only single (another folder), however all was fine. Questions -
> How can i trouble shoot what is causing the problem? i don't
> know where to begin.

We can help better if you show some of your code; a minimal
cut-down version that exhibits the error is ideal.

Are you literally getting a RuntimeError? That would be weird.

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


Re: Multiprocessing / threading confusion

2013-09-06 Thread Dave Angel
On 6/9/2013 14:27, Paul Pittlerson wrote:

f> Ok here is the fixed and shortened version of my script:
>
> #!/usr/bin/python
>
> from multiprocessing import Process, Queue, current_process
> from threading import Thread
> from time import sleep
>
> class Worker():
> def __init__(self, Que):
> self._pid = current_process().pid
> self.que = Que
> self.que.put('started worker %s' % self._pid)
> 
> for n in range(5):
> self.que.put('%s tick %d' % (self._pid, n))
> # do some work
> sleep(0.01)
> 
> self.que.put('%s has exited' % self._pid) 
> 
> class Debugger(Thread):
> def __init__(self, q):
> super(Debugger, self).__init__()
> self.q = q
> 
> def run(self):
> while True:
> 
> sleep(0.1)
> 
> if not self.q.empty():
> print self.q.get()
> 
> else:
> break
> #
>
> if __name__ == '__main__':
> 
> debug_q = Queue()
> debug = Debugger(debug_q)
> debug.start()
> 
> for i in range(5):
> 
> d = Process(target=Worker, args=(debug_q,))
> d.start()
>
> This works great on linux, but does not run on windows (7). The behavior was: 
> I 
> opened it with double clicking and so a window appeared and disappeared (no 
> text) then I opened it with IDLE and ran it there, where it worked a couple 
> times. Then reopened it with IDLE and this time it did not work at all. After 
> that the script did not run either through IDLE or opening directly.
>
> What may be the reason it works on linux, but seems buggy on windows?

In Linux, the Process() class works very differently.  One effect is
that it's probably much quicker than in Windows.  But also, the
relationship between the original process and the extra 5 is different.

I wouldn't even try to debug anything else till I add join() calls for
both the extra thread and the 5 extra processes.  You could just stick a
raw_input() at the end to fake it, but that's just a temporary hack.

Untested:


if __name__ == '__main__':

debug_q = Queue()
debug = Debugger(debug_q)
debug.start()

processes = []
for i in range(5):

d = Process(target=Worker, args=(debug_q,))
processes.append(d)
d.start()
for proc in processes:
proc.join()
debug.join()


As for running it in various shells, you missed the only one worth
using:  run it in the cmd shell.  When you double-click, you can't
really be sure if that temporary cmd shell was really empty before it
vanished;  it might just not have bothered to update its pixels on its
way out.  And any IDE shell like IDLE has so many other glitches in it,
that bugs like these are as likely to be the IDE's fault as anything
else.


-- 
DaveA


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


Re: Python KeyError

2013-09-06 Thread Ethan Furman

On 09/05/2013 01:37 AM, Robert Gliguroski wrote:


I have installed OpenERP, an open source ERP software and then I installed an 
extension for connecting it to Magento. But when I configure it and try to 
connect them, I am getting and error that says:
[snip]


You might try asking at either StackOverflow[0] or OpenERP's Q&A website[1].

[0] http://stackoverflow.com
[1] http://help.openerp.com

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


Re: Multiprocessing / threading confusion

2013-09-06 Thread Piet van Oostrum
Paul Pittlerson  writes:

[...]
> def run(self):
> while True:
> 
> sleep(0.1)
> 
> if not self.q.empty():
> print self.q.get()
> 
> else:
> break
[...]

> This works great on linux, but does not run on windows (7). The behavior was: 
> I 
> opened it with double clicking and so a window appeared and disappeared (no 
> text) then I opened it with IDLE and ran it there, where it worked a couple 
> times. Then reopened it with IDLE and this time it did not work at all. After 
> that the script did not run either through IDLE or opening directly.
>
> What may be the reason it works on linux, but seems buggy on windows?

That it works on Linux is just coincidence. Your script is still timing
dependent because the while loop in Debug.run stops when the queue is
empty. As has been explained in other answers, the queue can just become
empty when Debug empties it faster than the other processes can fill it.
That is entirely dependent on the scheduling of the O.S. so you have no
control over it. You must use a safe way to stop, for example to count
the exited messages.

Another way is to join all the processes in the main program, and after
that put a special END message to the queue, which causes Debug to stop:

class Debugger(Thread):
...
def run(self):
while True:
sleep(0.1)
msg = self.q.get()
print(msg)
if 'END' in msg:
break

..main..
processes = []
for i in range(5):

d = Process(target=Worker, args=(debug_q,))
d.start()
processes.append(d)

for p in processes:
p.join()
debug_q.put('END')

-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Confessions of a terrible programmer

2013-09-06 Thread Chris Angelico
On Sat, Sep 7, 2013 at 3:17 AM, Joel Goldstick  wrote:
> On Fri, Sep 6, 2013 at 12:56 PM, Steven D'Aprano
>  wrote:
>> Not specifically about Python, but still relevant:
>>
>> http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible-programmer.html
>>
>>
>>
>>
>>
>> --
>> Steven
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>
> Pardon me, but I completely don't get this article.  Let me in on what
> is supposed to be the joke please!

It's a "ha-ha only serious" article. The point is: You can't write
good code by being a good programmer. You MUST [1] acknowledge that
you write buggy code, and then code accordingly.

Sometimes you'll write bugs that result in egg on the face. I fixed
one this week that had been lying around for ages; if the user
provided a particular (and unusual, though not malformed) set of
input, and the program was running in the first hour after midnight
UTC on a Thursday, it would go into an infinite loop, because I'd
missed decrementing something. More often - especially if you do
things like the author there does - you'll have a program that bombs
really fast on startup, or at least bombs noisily when something goes
wrong. Those bugs are easy to find and, often, easy to fix. Those bugs
we can deal with.

The other point to note is that it takes a competent debugger to
figure out problems, and that's in many ways a more important skill
than writing code. Taking another example from this week at work: My
boss was tinkering with our AJAX system, using his Linux development
box and one of our Linux test servers. He clicks a button in either
Google Chrome or Iceweasel (Debian's old build of Firefox), the server
does stuff, and stuff happens promptly. He crosses over to his Windows
XP laptop to try the same button in IE8 (the oldest and stupidest
browser we support), and there's a 20-second lag before the server
does its stuff. But adding logging showed that the AJAX call was
taking less than a second, so it couldn't be that. Turned out the
request was given a job time based on the client's clock, which was 20
seconds ahead of the server, so the job got delayed by those 20
seconds. Would you, when debugging an AJAX+PHP system, think to check
if clocks are synchronized? Only if you know how to debug. Good
programmers can, and can pinpoint problems without looking at a single
line of code.

Claiming you'll write perfect code is arrogance beyond measure.
Acknowledging that there'll be bugs and building systems to cope with
(and remove) them is the critical humility for programmers.

[1] http://www.ietf.org/rfc/rfc2119.txt

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


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

2013-09-06 Thread roggero . n
shut off the HD, start the SO form an USB and shut on again the HD

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


Re: Confessions of a terrible programmer

2013-09-06 Thread Steven D'Aprano
On Fri, 06 Sep 2013 13:17:20 -0400, Joel Goldstick wrote:

> On Fri, Sep 6, 2013 at 12:56 PM, Steven D'Aprano
>  wrote:
>> Not specifically about Python, but still relevant:
>>
>> http://blog.kickin-the-darkness.com/2007/09/confessions-of-terrible-
programmer.html

> Pardon me, but I completely don't get this article.  Let me in on what
> is supposed to be the joke please!


It isn't intended as a joke. The article is serious, but it wraps its 
serious message in a bit of mild humour: here is a guy who calls himself 
a terrible programmer, but his projects are always completed on time and 
on budget, while "good" programmers' projects are late, over-budget and 
buggy.

The irony is that those who think of themselves as "good programmers" end 
up writing worse code than those who think of themselves as "terrible 
programmers", because the self-aware terrible programmers use all the 
tools in the programmer toolbox to improve their code and the others 
don't.

The author of that blog piece is too polite to say so, but I suspect that 
there's a certain amount of Dunning-Kruger Effect going on...

http://en.wikipedia.org/wiki/Dunning–Kruger_effect

but I digress.


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


Re: can't find win32api from embedded pyrun call

2013-09-06 Thread David M. Cotter
the problem was: ActivePython does not install debug libraries, so you must 
link with release libraries in your project.  but if you run the debug version, 
you're linking against debug libraries which conflict with the ones linked to 
by python.  

"fixed" by running the release version.  basically, it's not possible to debug 
with ActivePython due to ActiveState not including debug libs.  grr
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: file handling issues

2013-09-06 Thread Leo Carnovale
On Saturday, 7 September 2013 02:17:03 UTC+10, Piet van Oostrum  wrote:
> leo.carnov...@gmail.com writes:
> 
> 
> 
> > I am making this little game and I am trying to make some sort of script 
> > that does the following:
> 
> >>Checks to see if a file exists
> 
> >  >If it does, check the numbers in it
> 
> >  >If it doesn't, make one and fill it with some numbers
> 
> >>Sorts out if the numbers in the file are in the right format
> 
> >  >If they are, then store them
> 
> >  >If not, remake it again
> 
> >>THEN, check if there is a pass.
> 
> >  >If there is, check if it fits the key and go on if so
> 
> >  >If not, ask for a new one, check it, go on if its correct.
> 
> >
> 
> > Every time I run it, it says the key is 0!?
> 
> > I can not for the life of me figure out what it is doing.
> 
> >
> 
> > The code:
> 
> > 
> 
> >
> 
> 
> 
> What a mess is that code. First that messing around with the key is
> 
> crazy. You probably want to do some crypto on it, but why don't you just
> 
> use some standard crypto algorithm?
> 
> 
> 
> The you have defined T as True and F as False, but sometimes you use T
> 
> and sometimes True, and as far as I can see you never use F. Just stay
> 
> with True and false as it makes the code more readable.
> 
> 
> 
> Once you use "with open('Key')", all other case you use
> 
> f = open('Key',...)
> 
> f.read() or f.write()
> 
> f.close()
> 
> 
> 
> Be consistenst and use always "with open..."
> 
> 
> 
> There are at least three palces where you write a key to the file. Make
> 
> a function for this; it makes your code more structured.
> 
> 
> 
> And please, put spaces aroud the = signs.
> 
> 
> 
> Now the real problem:
> 
> 
> 
> if newpas:
> 
> f=open("Key","w")
> 
> print("No pass found!")
> 
> print("Your wonderful key is: ",int(keys[0]))
> 
> pasw=input("What is your pass?   : ")
> 
> elif newkey:
> 
> f=open("Key","w")
> 
> 
> 
> Here you open the file for writing but you never write anything to it.
> 
> This makes the file empty. And apparently you do not check this the next
> 
> time you open it. If you would have used a function to write a key to
> 
> the file, this probably would not have occurred.
> 
> 
> 
> if mess_with(keys[0])==pasw:
> 
> hesin=1
> 
> print("Your in!")
> 
> f=open("Key","w")
> 
> 
> 
> Here you open the file again with the same variable. This causes the old
> 
> value to be lost and the file probably to be closed. Just messy.
> 
> 
> 
> print("writing %s" % str(keys[0])+pasw)
> 
> f.write(str(keys[0])+pasw)
> 
> f.close()
> 
> else:
> 
> hesin=0
> 
> 
> 
> And how are people supposed to guess an 8 character password? Are they
> 
> supposed to do that weird calculation on their calculators or some such?
> 
> 
> 
> -- 
> 
> Piet van Oostrum 
> 
> WWW: http://pietvanoostrum.com/
> 
> PGP key: [8DAE142BE17999C4]

Yes the code is a mess, I have been tempted to re write the whole thing...
The reason for the messiness is firstly because I am relatively new to 
programming and because this is the result of me tinkering around with previous 
code, which was still messy, but cleaner than this.

So the open("key","w") clears the file straight away? That helps a lot, thanks, 
this will definitely save me a lot of time in the future. Also the user doesn't 
guess the pass, I would give it to them. After they enter it, they go on to the 
guessing game (not shown in the code).

Thanks for the help!

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


Re: file handling issues

2013-09-06 Thread Leo Carnovale
On Saturday, 7 September 2013 13:03:14 UTC+10, Leo Carnovale  wrote:
> On Saturday, 7 September 2013 02:17:03 UTC+10, Piet van Oostrum  wrote:
> 
> > leo.carnov...@gmail.com writes:
> 
> > 
> 
> > 
> 
> > 
> 
> > > I am making this little game and I am trying to make some sort of script 
> > > that does the following:
> 
> > 
> 
> > >>Checks to see if a file exists
> 
> > 
> 
> > >  >If it does, check the numbers in it
> 
> > 
> 
> > >  >If it doesn't, make one and fill it with some numbers
> 
> > 
> 
> > >>Sorts out if the numbers in the file are in the right format
> 
> > 
> 
> > >  >If they are, then store them
> 
> > 
> 
> > >  >If not, remake it again
> 
> > 
> 
> > >>THEN, check if there is a pass.
> 
> > 
> 
> > >  >If there is, check if it fits the key and go on if so
> 
> > 
> 
> > >  >If not, ask for a new one, check it, go on if its correct.
> 
> > 
> 
> > >
> 
> > 
> 
> > > Every time I run it, it says the key is 0!?
> 
> > 
> 
> > > I can not for the life of me figure out what it is doing.
> 
> > 
> 
> > >
> 
> > 
> 
> > > The code:
> 
> > 
> 
> > > 
> 
> > 
> 
> > >
> 
> > 
> 
> > 
> 
> > 
> 
> > What a mess is that code. First that messing around with the key is
> 
> > 
> 
> > crazy. You probably want to do some crypto on it, but why don't you just
> 
> > 
> 
> > use some standard crypto algorithm?
> 
> > 
> 
> > 
> 
> > 
> 
> > The you have defined T as True and F as False, but sometimes you use T
> 
> > 
> 
> > and sometimes True, and as far as I can see you never use F. Just stay
> 
> > 
> 
> > with True and false as it makes the code more readable.
> 
> > 
> 
> > 
> 
> > 
> 
> > Once you use "with open('Key')", all other case you use
> 
> > 
> 
> > f = open('Key',...)
> 
> > 
> 
> > f.read() or f.write()
> 
> > 
> 
> > f.close()
> 
> > 
> 
> > 
> 
> > 
> 
> > Be consistenst and use always "with open..."
> 
> > 
> 
> > 
> 
> > 
> 
> > There are at least three palces where you write a key to the file. Make
> 
> > 
> 
> > a function for this; it makes your code more structured.
> 
> > 
> 
> > 
> 
> > 
> 
> > And please, put spaces aroud the = signs.
> 
> > 
> 
> > 
> 
> > 
> 
> > Now the real problem:
> 
> > 
> 
> > 
> 
> > 
> 
> > if newpas:
> 
> > 
> 
> > f=open("Key","w")
> 
> > 
> 
> > print("No pass found!")
> 
> > 
> 
> > print("Your wonderful key is: ",int(keys[0]))
> 
> > 
> 
> > pasw=input("What is your pass?   : ")
> 
> > 
> 
> > elif newkey:
> 
> > 
> 
> > f=open("Key","w")
> 
> > 
> 
> > 
> 
> > 
> 
> > Here you open the file for writing but you never write anything to it.
> 
> > 
> 
> > This makes the file empty. And apparently you do not check this the next
> 
> > 
> 
> > time you open it. If you would have used a function to write a key to
> 
> > 
> 
> > the file, this probably would not have occurred.
> 
> > 
> 
> > 
> 
> > 
> 
> > if mess_with(keys[0])==pasw:
> 
> > 
> 
> > hesin=1
> 
> > 
> 
> > print("Your in!")
> 
> > 
> 
> > f=open("Key","w")
> 
> > 
> 
> > 
> 
> > 
> 
> > Here you open the file again with the same variable. This causes the old
> 
> > 
> 
> > value to be lost and the file probably to be closed. Just messy.
> 
> > 
> 
> > 
> 
> > 
> 
> > print("writing %s" % str(keys[0])+pasw)
> 
> > 
> 
> > f.write(str(keys[0])+pasw)
> 
> > 
> 
> > f.close()
> 
> > 
> 
> > else:
> 
> > 
> 
> > hesin=0
> 
> > 
> 
> > 
> 
> > 
> 
> > And how are people supposed to guess an 8 character password? Are they
> 
> > 
> 
> > supposed to do that weird calculation on their calculators or some such?
> 
> > 
> 
> > 
> 
> > 
> 
> > -- 
> 
> > 
> 
> > Piet van Oostrum 
> 
> > 
> 
> > WWW: http://pietvanoostrum.com/
> 
> > 
> 
> > PGP key: [8DAE142BE17999C4]
> 
> 
> 
> Yes the code is a mess, I have been tempted to re write the whole thing...
> 
> The reason for the messiness is firstly because I am relatively new to 
> programming and because this is the result of me tinkering around with 
> previous code, which was still messy, but cleaner than this.
> 
> 
> 
> So the open("key","w") clears the file straight away? That helps a lot, 
> thanks, this will definitely save me a lot of time in the future. Also the 
> user doesn't guess the pass, I would give it to them. After they enter it, 
> they go on to the guessing game (not shown in the code).
> 
> 
> 
> Thanks for the help!
> 
> 
> 
> Leo

Ah and one other thing!
What is this crypto algorithm you speak of? I desperately need some sort of 
encryption as at the moment anyone can simply open the text file and change the 
numbers to numbers that work! 
Where can I learn more about it?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: file handling issues

2013-09-06 Thread Michael Torrie
On 09/06/2013 09:05 PM, Leo Carnovale wrote:
> Ah and one other thing! What is this crypto algorithm you speak of? I
> desperately need some sort of encryption as at the moment anyone can
> simply open the text file and change the numbers to numbers that
> work! Where can I learn more about it?

There are two kinds of cryptography, generally.  Symmetric and
asymmetric.  Your needs will dictate which system you use.  Symmetric
cryptography means that the sake encryption key that was used to encrypt
the data is used to decrypt it.  Asymmetric cryptography basically means
one key is used to encrypt a message and another key is used to decrypt
the message.

In your case, perhaps symmetric encryption is most logical, though I'm
not at all clear what you are doing.  However you'll have to embed the
encryption key in your python source code, which isn't hidden at all.
And actually any program that embeds a symmetric key in its code can be
cracked rather easily.

Python has many libraries to support encryption.  Some are in the
standard library.  Search for python and crypto to see what docs are
available.  You might want to read up on basic cryptography principles
as well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Installing resource data files and finding them

2013-09-06 Thread Ben Finney
Howdy all,

How do I package a Python application with its resource files separate
from the Python modules, such that the resource files can be discovered
by the Python code when it runs?


I am working on an existing Python application code base. The
application currently assumes that its resource files will be installed
to the same location as the python modules (using the Distutils
‘package_data’ option).

But this violates the Filesystem Hierarchy Standard used on GNU+Linux
http://refspecs.linuxfoundation.org/FHS_2.3/fhs-2.3.html>. By that
standard, platform-independent resources belong in ‘/usr/share/…’, while
platform-dependent code libraries belong in ‘/usr/lib/…’.

Currently the upstream Python code uses ‘os.path.dirname(__file__)’ and
similar, to discover the location of the resource files. It thereby
assumes that the resource files are installed to the same location as
the Python code. The Distutils ‘package_data’ option appears to enforce
this, and I can't find any way for the files to be installed to a
different place using that option.

The Distutils ‘data_files’ option doesn't seem suitable for this
purpose. It allows the location to be specified (using ‘python
./setup.py --data-files=FOODIR’),, but there appears to be no way for
the application to know what location was specified later.

I will need to change both the build configuration and the application
code, so that instead it allows the resource files to be installed to an
appropriate location on the target system, and seeks the data files in
the correct location when run later.


Of course, the code should continue to work on systems that don't
conform to the FHS and allow resource data files to live alongside
platform code, so I can't just hard-code the new location.

I had hoped to use Python's standard library (Distutils? Distribute?
Something else?) to access the resources once installed to the correct
location. This needs to allow the choice of location to be made at
install-time, but discovered by the application at run-time.

Is there a way to do that, or is this a problem still unsolved in
Python?

-- 
 \“Most people, I think, don't even know what a rootkit is, so |
  `\ why should they care about it?” —Thomas Hesse, Sony BMG, 2006 |
_o__)  |
Ben Finney

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


Re: file handling issues

2013-09-06 Thread Leo Carnovale
On Saturday, 7 September 2013 13:58:43 UTC+10, Michael Torrie  wrote:
> On 09/06/2013 09:05 PM, Leo Carnovale wrote:
> 
> > Ah and one other thing! What is this crypto algorithm you speak of? I
> 
> > desperately need some sort of encryption as at the moment anyone can
> 
> > simply open the text file and change the numbers to numbers that
> 
> > work! Where can I learn more about it?
> 
> 
> 
> There are two kinds of cryptography, generally.  Symmetric and
> 
> asymmetric.  Your needs will dictate which system you use.  Symmetric
> 
> cryptography means that the sake encryption key that was used to encrypt
> 
> the data is used to decrypt it.  Asymmetric cryptography basically means
> 
> one key is used to encrypt a message and another key is used to decrypt
> 
> the message.
> 
> 
> 
> In your case, perhaps symmetric encryption is most logical, though I'm
> 
> not at all clear what you are doing.  However you'll have to embed the
> 
> encryption key in your python source code, which isn't hidden at all.
> 
> And actually any program that embeds a symmetric key in its code can be
> 
> cracked rather easily.
> 
> 
> 
> Python has many libraries to support encryption.  Some are in the
> 
> standard library.  Search for python and crypto to see what docs are
> 
> available.  You might want to read up on basic cryptography principles
> 
> as well.

Thanks! Obviously, I need to do a lot of research. 
-- 
https://mail.python.org/mailman/listinfo/python-list