[RELEASED] Python 3.3.3 release candidate 2

2013-11-12 Thread Georg Brandl
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On behalf of the Python development team, I'm quite happy to announce the
Python 3.3.3 release candidate 2.

Python 3.3.3 includes several security fixes and over 150 bug fixes compared to
the Python 3.3.2 release.

This release fully supports OS X 10.9 Mavericks.  In particular, this release
fixes an issue that could cause previous versions of Python to crash when typing
in interactive mode on OS X 10.9.

Python 3.3 includes a range of improvements of the 3.x series, as well as easier
porting between 2.x and 3.x.  In total, almost 500 API items are new or improved
in Python 3.3.  For a more extensive list of changes in the 3.3 series, see

http://docs.python.org/3.3/whatsnew/3.3.html

To download Python 3.3.3 rc2 visit:

http://www.python.org/download/releases/3.3.3/


This is a preview release, please report any bugs to

 http://bugs.python.org/


Enjoy!

- --
Georg Brandl, Release Manager
georg at python.org
(on behalf of the entire python-dev team and 3.3's contributors)
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.22 (GNU/Linux)

iEYEARECAAYFAlKB1G4ACgkQN9GcIYhpnLAu5gCfRkfpnEs+rmtZ9iTjaaZcHDx3
sNYAn180Q4cFZmKtwJdaG+g/3jHAVd97
=n/Tt
-END PGP SIGNATURE-
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Getting globals of the caller, not the defining module

2013-11-12 Thread Rotwang

On 12/11/2013 01:57, Terry Reedy wrote:

On 11/11/2013 7:02 AM, sg...@hotmail.co.uk wrote:

(Sorry for posting through GG, I'm at work.)

On Monday, November 11, 2013 11:25:42 AM UTC, Steven D'Aprano wrote:

Suppose I have a function that needs access to globals:

# module A.py
def spam():
 g = globals()  # this gets globals from A
 introspect(g)

As written, spam() only sees its own globals, i.e. those of the
module in
which spam is defined. But I want spam to see the globals of the caller.

# module B
import A
A.spam()  # I want spam to see globals from B

I can have the caller explicitly pass the globals itself:

def spam(globs=None):
 if globs is None:
 globs = globals()
 introspect(globs)

But since spam is supposed to introspect as much information as
possible,
I don't really want to do that. What (if anything) are my other options?


How about this?

# module A.py
import inspect
def spam():
 return inspect.stack()[1][0].f_globals


In Python 3, the attribute is __globals__.


Er... no it isn't? Sorry if I'm mistaken but I believe you're thinking 
of the attribute formerly known as func_globals. But in the above 
inspect.stack()[1][0] is not a function, it's a frame object. In fact 
it's the same thing as sys._getframe().f_back, I think.

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


Re: Conditional breakpoints in ceval.c

2013-11-12 Thread David Froger
Quoting Ned Batchelder (2013-11-09 14:24:34)
 On Friday, November 8, 2013 9:03:51 PM UTC-5, Demian Brecht wrote:
  Hi all,
  
  I have an .py file with a simple assignment in it:
  foo = 'bar'
  
  Now, I want to set a conditional breakpoint in gdb, breaking on that
  assignment (I'm guessing the top of the stack would be breaking on the
  LOAD_CONST with a value or 'bar'). How would I go about doing that?
  
  b ceval.c:1368 if [?]
  
  Thanks,
  
  -- 
  Demian Brecht
  http://demianbrecht.github.com
 
 I don't know how to use gdb the way you want, but it sounds like you are on a 
 fascinating journey of discovery.  What are you trying to learn?  Perhaps we 
 can talk about how the interpreter works.
 
 --Ned.
 -- 
 https://mail.python.org/mailman/listinfo/python-list

Hi all,

In the purpose of debugging C/C++ Python extensions, I've been also looking for
a way to put a gdb breakpoint on a Python line file, like this:
(gdb) b foo.py:47
But I have no idea how this could be implemented.

To break in a C/C++ extension with gdb, on can declare a function, for
example 'Py_DebugTrap' [1], and call it call in the C/C++ code where he/she
want to break, then in gdb:
(gdb) b Py_DebugTrap

So a altenative to break into Python could be to do the same: wrap the
Py_DebugTrap in a Python module, then in the Python file, call the trap
function, for example:
import gdbbreak
gdbbreak.breakpoint_here()
foo = 'bar'

The function gdbbreak.breakpoint_here() would just call the 'Py_DebugTrap'
function, and then in gdb:
(gdb) b Py_DebugTrap
(gdb) next # until foo = 'bar' assignement is reach

(I never try this, be it should work.)

[1] 
http://joyrex.spc.uchicago.edu/bookshelves/python/cookbook/pythoncook-CHP-16-SECT-8.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: To whoever hacked into my Database

2013-11-12 Thread Antoon Pardon
Op 12-11-13 07:31, ru...@yahoo.com schreef:
 On 11/11/2013 06:16 PM, Ned Batchelder wrote:
 On Monday, November 11, 2013 5:47:28 PM UTC-5, ru...@yahoo.com wrote:
 On 11/08/2013 11:08 AM, Chris Angelico wrote:
 On Sat, Nov 9, 2013 at 4:11 AM,  ru...@yahoo.com wrote:
 On 11/08/2013 03:05 AM, Νίκος Αλεξόπουλος wrote:
 I never ignore advices. I read all answers as carefully as i
 can. But nevertheless sometimes i feel things should have
 been better implemented using my way.

 Not of course that i know better, but thats better suited for
 me in the level iam.

 Most of the advice I've seen posted here has, as far as I can
 tell, not intended to be useful but to serve as a way to
 telling you are incompetent are in other ways insulting or
 useless.  I think you are quite right to ignore it (or tell the
 poster to get lost.)

 Actually no; most of the advice has been genuine.

 Actually yes; most of the advice has not been genuine.

 rurpy, I applaud your efforts to make this forum more civil.  I do
 not like the general tone of the responses to Nikos these days.  But
 you are being naive to present this as the big bad meanies against
 the innocent OP.
 
 I never claimed Nikos was innocent.  I was complaining 
 about responses, driven by frustration or hostility, that 
 go beyond reasonable and become so dogmatic and absolutist 
 that they themselves become wrong.  Nikos (or anyone else) 
 is right to reject such responses.

So you are complaining about people being human. Yes that is
how people tend to react when they continualy are frustrated
by someone who refuses to show the slightest cooperation.
So no rejecting such responses, particullarly by the person
who caused them is not right. It is defelecting the blame from
the primal cause.

 Nikos has received a good deal of genuine advice.  He has also been
 genuinely difficult to help.
 
 Yes.  If he is too difficult to help without getting
 angry because he won't do what you (generic) tell him
 then perhaps a more constructive response is to stop
 trying to help him rather than join the lynch mob that
 is making the atmosphere here far worse (IMO) than
 Nikos alone could.  However, I have made that argument
 in the past and am not interested in rearguing it.

That is correct but is expecting too much from people in general.
Expecting from frustrated people to act rational and constructive
is just a recipe for your own frustrations. And your own reaction
illustrates the problem beautifully because you come with an
irrational non-constructive proposal, that is very unlikely to
motivate people in actually want to cooperate with you in getting
this community to be more positive again.

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


Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Frank-Rene Schäfer
(1) hash()-ability != immutability (!)

Proof:

class X:
def __hash__(self): return 0

def pseudo_isimmutable(this):
try:
hash(this)
return True
except TypeError:
return False

shapeshifter = (1, 2, X())
print pseudo_isimmutable(shapeshifter)
shapeshifter[2].changed = 4711


(2) The intended scenario is not described by a fragment such as:

  if isimmutable(obj): x = obj
  else: x = copy.copy(obj)
  function_that_might_modify(x)

But instead, a more characteristic scenario is

 assert isimmutable(obj)
 # What happens behind the curtain may rely on referencing
 things_behind_the_curtain(obj)

Or,

def let_me_know():
 obj = get_what_is_wanted()
 assert isimmutable(obj)
 # The caller may do with it what he wants without risking consistency
 return obj

where lots of copying





2013/11/11  random...@fastmail.us:
 A built-in function 'isimmutable()' shall tell efficiently whether the
 object
 of concern is mutable or not.

 What's the benefit over attempting to hash() the object?

 copy.deepcopy already has special case for int, string, and tuples
 (including tuples that do and do not have mutable members) - could what
 you need be accomplished by overriding __copy__ and __deepcopy__ in your
 custom class to return itself if it is immutable?

2013/11/11  random...@fastmail.us:
 A built-in function 'isimmutable()' shall tell efficiently whether the
 object
 of concern is mutable or not.

 What's the benefit over attempting to hash() the object?

 copy.deepcopy already has special case for int, string, and tuples
 (including tuples that do and do not have mutable members) - could what
 you need be accomplished by overriding __copy__ and __deepcopy__ in your
 custom class to return itself if it is immutable?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UTF-32 decoder optimization in Python 3.4

2013-11-12 Thread Mark Lawrence

On 12/11/2013 02:11, Terry Reedy wrote:

On 11/11/2013 4:41 PM, Mark Lawrence wrote:

 From http://docs.python.org/dev/whatsnew/3.4.html#optimizations The
UTF-32 decoder is now 3x to 4x faster..  Does anybody have any
references to this work?  All I can find is the 3.3 what's new which
refers to PEP 393 (Flexible String Representation) optimizations as a
result of work done by Serhiy Storchaka on issues 14624, 14738 and 15026.


The second line at the top has For full details, see the changelog.
where changelog links to
http://docs.python.org/3.4/whatsnew/changelog.html
Searching that for 'UTF-34' goes to this line
Issue #14625: Rewrite the UTF-32 decoder. It is now 3x to 4x faster.
Patch written by Serhiy Storchaka. where 'Issue #14625' links to
http://bugs.python.org/issue14625
with full discussion. (I know that you, Mark, could have found that, but
not everyone reading could.)



Thanks for pointing out the obvious Terry. Kicks self up bum rather than 
facepalm :(


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Chris Angelico
On Tue, Nov 12, 2013 at 8:12 PM, Frank-Rene Schäfer fsch...@gmail.com wrote:
 (1) hash()-ability != immutability (!)

 Proof:

 class X:
 def __hash__(self): return 0


x == y != y == x

Proof:

class X:
   def __eq__(self,other): return True
class Y:
   def __eq__(self,other): return False

All you've done is proven that you can subvert things. By fiddling
with __hash__, __eq__, and so on, you can make sets and dicts behave
very oddly. Means nothing.

Fundamentally, your mutability check is going to need some form of
assistance from user-defined classes. That means a class can break
your rules.

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


Re: datetime question

2013-11-12 Thread Mark Lawrence

On 12/11/2013 07:25, alex23 wrote:

On 12/11/2013 2:49 PM, Grant Edwards wrote:

Don't forget that there are also some differences between American and
Imperial whitespace.  Since it's ASCII whitespace, you should probably
assume American...


  sys.getsizeof(' ')
34
  sys.getsizeof(u' ')
52

bad by design


Don't you start :)

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: To whoever hacked into my Database

2013-11-12 Thread Mark Lawrence

On 12/11/2013 05:21, Gregory Ewing wrote:

Ned Batchelder wrote:

I don't know how best to make things better overall.  I know that
overlooking Nikos' faults won't do it.


If everyone who reached the point where they don't think
they can help any more would simply say so in a calm
manner and then walk away, that would make things better
overall. It wouldn't help *Nikos*, but it would prevent
the discussion from degenerating into a flamefest.

It takes two to spiral.



In this case three, the OP, the spoon feeders who've tried so hard to 
help on so many occasions, but have consistently seen their help 
rejected, and the responders who finally get fed up.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: To whoever hacked into my Database

2013-11-12 Thread Dotan Cohen
On Fri, Nov 8, 2013 at 7:11 PM,  ru...@yahoo.com wrote:
 Long before you showed up here, I noticed the tendency
 to not answer questions directly but to jerk people off
 by giving hints or telling them to do something other
 than they want to do.

 Often that is good because the original request was
 for something that the OP really didn't want to do.
 But sometimes the OP knows they want to do (but doesn't
 want or is unable to clearly explain why) and when
 they clearly state that, yes, they do want to do it
 their way, their question should be answered in good
 faith or, for those who just can't tell how to do
 something wrong, ignored.

 Instead the response is typically a lot of hostility
 directed at them for not taking advice.  In other
 words, the advice here is not free advice, but come
 with the price that you are expected to except it
 gratefully whether it was what you asked for or not.

 I think you are quite right to reject advice that does
 not do what you want and ask again for advice that does.

 FWIW, I am quite sure there are other readers of this
 group who feel the same way, but most people aren't
 willing to subject themselves to the bullying that
 will be directed at anyone who publicly agrees with you.
 It is the same way in real life too as I'm sure
 you know.

 Just wanted to let you know that not everybody here
 is an asshole.  It is just that assholes, by their
 nature, are the loudest.

When I've been given advice on this list or others that does not
directly answer my question, I've found that the advice comes from one
of two types of posters:
1) Those who don't understand my question, possibly due to my own
failure to properly articulate.
-or-
2) Those who understand my predicament better than I do, and show my
how to get the results that I need despite my own failure to
understand what exactly I need.

With Python specifically, the latter far outnumber the former. When
somebody here is giving advice, I listen humbly. Likewise I advise any
newcomer to do.

-- 
Dotan Cohen

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


Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Frank-Rene Schäfer
 All you've done is proven that you can subvert things. By fiddling
 with __hash__, __eq__, and so on, you can make sets and dicts behave
 very oddly. Means nothing.

To the contrary, it means everything about what 'isimmutable' could
contribute: security against advert or inadvert insertion of mutable objects.


2013/11/11  random...@fastmail.us:
 A built-in function 'isimmutable()' shall tell efficiently whether the
 object
 of concern is mutable or not.

 What's the benefit over attempting to hash() the object?

 copy.deepcopy already has special case for int, string, and tuples
 (including tuples that do and do not have mutable members) - could what
 you need be accomplished by overriding __copy__ and __deepcopy__ in your
 custom class to return itself if it is immutable?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: To whoever hacked into my Database

2013-11-12 Thread Chris Angelico
On Tue, Nov 12, 2013 at 8:34 PM, Mark Lawrence breamore...@yahoo.co.uk wrote:
 On 12/11/2013 05:21, Gregory Ewing wrote:

 Ned Batchelder wrote:

 I don't know how best to make things better overall.  I know that
 overlooking Nikos' faults won't do it.


 If everyone who reached the point where they don't think
 they can help any more would simply say so in a calm
 manner and then walk away, that would make things better
 overall. It wouldn't help *Nikos*, but it would prevent
 the discussion from degenerating into a flamefest.

 It takes two to spiral.


 In this case three, the OP, the spoon feeders who've tried so hard to help
 on so many occasions, but have consistently seen their help rejected, and
 the responders who finally get fed up.

And then it all goes meta. This thread hasn't had anything productive
for quite some time now... nor even anything funny.

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


Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Chris Angelico
On Tue, Nov 12, 2013 at 8:39 PM, Frank-Rene Schäfer fsch...@gmail.com wrote:
 All you've done is proven that you can subvert things. By fiddling
 with __hash__, __eq__, and so on, you can make sets and dicts behave
 very oddly. Means nothing.

 To the contrary, it means everything about what 'isimmutable' could
 contribute: security against advert or inadvert insertion of mutable objects.

So how do you figure out whether something's immutable or not? Are you
going to ask the object itself? If so, stick with __hash__, and just
follow the rule that mutable objects aren't hashable - which is, if
I'm not mistaken, how things already are. And if not, then how? How
will you know if something has mutator methods?

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


Re: Creating a function for a directory

2013-11-12 Thread unknown
On Mon, 11 Nov 2013 14:26:46 -0800, Matt wrote:

 So I want to take the file, desktop/test.txt and write it to
 desktop/newfolder/test.txt. I tried the below script, and it gave me:
 IOError: [Errno 2] No such file or directory: 'desktop/%s.txt'. Any
 suggestions would be great.
 
 
 
 def firstdev(file):
   in_file = open(desktop/%s.txt) % file indata = in_file.read()
   out_file = open(desktop/newfolder/%s.txt, 'w') % file
   out_file.write(indata)
   out_file.close()
   in_file.close()
   
 firstdev(test)

would it not be more efficient and less error prone to use the os module 
to copy the file rather than manually reading  re-writing it (unless of-
course you intend to expand this in future to process the data first)?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Ferrous Cranus

Στις 8/11/2013 11:11 μμ, ο/η Νίκος Αλεξόπουλος έγραψε:

Is there someway to write the following line even better with the
ability to detect daylight saving time by itself so i don't have to
alter the line manually when time changes?

lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
'%y-%m-%d %H:%M:%S' )# MySQL datetime format

Thanks.



Example:

#check if date entered as intented, format it properly for MySQL
lastvisit = datetime.strptime(lastvisit, '%d %m %Y').strftime('%Y-%m-%d')

The above code gets the datetime string in a specific way and then 
convert it to another format. All happens in one line clear and simple.


Now, in the following statement there shopuld be some way to check for 
daylight saving time so i would aboiut add +2 in winter or +3 for greek 
summer time.


lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime( 
'%y-%m-%d %H:%M:%S' )		# MySQL datetime format


I think + timedelta(hours=2) should be substituted with something else 
but i don't with what.

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


Re: To whoever hacked into my Database

2013-11-12 Thread Antoon Pardon
Op 12-11-13 10:35, Chris Angelico schreef:
 On Tue, Nov 12, 2013 at 8:34 PM, Mark Lawrence breamore...@yahoo.co.uk 
 wrote:
 On 12/11/2013 05:21, Gregory Ewing wrote:

 Ned Batchelder wrote:

 I don't know how best to make things better overall.  I know that
 overlooking Nikos' faults won't do it.


 If everyone who reached the point where they don't think
 they can help any more would simply say so in a calm
 manner and then walk away, that would make things better
 overall. It wouldn't help *Nikos*, but it would prevent
 the discussion from degenerating into a flamefest.

 It takes two to spiral.


 In this case three, the OP, the spoon feeders who've tried so hard to help
 on so many occasions, but have consistently seen their help rejected, and
 the responders who finally get fed up.
 
 And then it all goes meta. This thread hasn't had anything productive
 for quite some time now... nor even anything funny.

Well if people disagree about what kind of response is appropiate, then
I think discussing that, is productive. At least it is more productive
than trying to be funny.

-- 
Antoon Pardon

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


Re: Creating a function for a directory

2013-11-12 Thread Peter Otten
unknown wrote:

 On Mon, 11 Nov 2013 14:26:46 -0800, Matt wrote:
 
 So I want to take the file, desktop/test.txt and write it to
 desktop/newfolder/test.txt. I tried the below script, and it gave me:
 IOError: [Errno 2] No such file or directory: 'desktop/%s.txt'. Any
 suggestions would be great.
 
 
 
 def firstdev(file):
 in_file = open(desktop/%s.txt) % file indata = in_file.read()
 out_file = open(desktop/newfolder/%s.txt, 'w') % file
 out_file.write(indata)
 out_file.close()
 in_file.close()
 
 firstdev(test)
 
 would it not be more efficient and less error prone to use the os module
 to copy the file rather than manually reading  re-writing it (unless of-
 course you intend to expand this in future to process the data first)?

Hmm, I don't see a suitable function in os -- but there is 

shutil.copy()

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


Re: Basic Python Questions - Oct. 31, 2013

2013-11-12 Thread E.D.G.
E.D.G. edgrs...@ix.netcom.com wrote in message 
news:yo-dnwfmi7_7d-jpnz2dnuvz_hqdn...@earthlink.com...


Posted by E.D.G. on November 12, 2013

  The following is part of a note that I just posted to the Perl 
Newsgroup.  But it is actually intended for all computer programmers who are 
circulating free download software.


  One of the people that I work with and I are using an important 
computer program that is quite unique.  It was created a long time ago by a 
highly regarded scientist who passed away a while back.  And he made three 
copies of the program available for people as free downloads.  The first is 
an exe version of the program that will run on any Windows machine.  The 
second is the code for the program written using what is now an ancient 
version of Fortran.   And the third is for the same program using an ancient 
version of Basic.


  The professional programmer and I attempted to produce versions of 
the program using a modern language.  I managed the project and the 
programmer did the actual work.  And unfortunately, in spite of his many 
years of experience he could not understand the Fortran and Basic versions 
to the point where he could translate them.  I recommended that he post some 
notes to the Fortran Newsgroup and ask if anyone visiting that Newsgroup had 
an instruction manual for that ancient version of Fortran that would explain 
what the program code meant.  But for some reason he chose not to do that. 
And it would have taken me a considerable amount of time to attempt the 
translation myself.


  So, the end result is that when the program needs to generate data, 
the exe version is used as is.  Or it is called from a Perl program and 
given the input information it needs so that it can generate data.


  The point is, when people want to make some computer program 
available for use by others around the world they might want to circulate a 
version of their program that has such a simple format that anyone can 
understand it.  And for actual use they can generate parallel versions that 
have more efficient code that people who are working with that language can 
understand.


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


Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Frank-Rene Schäfer
 So how do you figure out whether something's immutable or not? Are you
 going to ask the object itself? If so, stick with __hash__, and just
 follow the rule that mutable objects aren't hashable - which is, if
 I'm not mistaken, how things already are. And if not, then how? How
 will you know if something has mutator methods?

Admittedly, I have no knowledge about the python implementation. A possible
way would be to say:

def isimmutable(this):
 if isinstance(this, tuple):
  for x in this:
  if not isimmutable(x): return False
  return True
 return isisintance(this, (int, str, ImmutableNester))

The ImmutableNester special class type would be a feature to help checks
to avoid recursion. Objects of classes derived from ImmutableNester have no
mutable access functions and allow insertion of members only at construction
time. At construction time it checks whether all entered elements are immutable
in the above sense.

As said, I have no idea how much this fits into the general python
implementation.


2013/11/11  random...@fastmail.us:
 A built-in function 'isimmutable()' shall tell efficiently whether the
 object
 of concern is mutable or not.

 What's the benefit over attempting to hash() the object?

 copy.deepcopy already has special case for int, string, and tuples
 (including tuples that do and do not have mutable members) - could what
 you need be accomplished by overriding __copy__ and __deepcopy__ in your
 custom class to return itself if it is immutable?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Steven D'Aprano
On Tue, 12 Nov 2013 18:12:43 +1100, Chris Angelico wrote:

 def isimmutable(x):
 try:
 hash(x)
 return True
 except TypeError:
 return False

I'm afraid that doesn't test for immutability. It tests for hashability, 
which is different.

No well-behaved mutable object can be hashable, but that's not to say 
that badly-behaved mutable objects won't be hashable. And every immutable 
object should be hashable, but that's not to say that some immutable 
objects might choose, for their own reasons, not to be hashable.

So your function is subject to both false negatives and false positives.


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


Re: PyMyth: Global variables are evil... WRONG!

2013-11-12 Thread Ricardo Aráoz

El 12/11/13 01:46, Rick Johnson escribió:
No, Python modules can be poked, prodded, and violated by any pervert 
who can spell the word import. Attribute values can be reassigned 
and state can be externally manipulated resulting in all types of 
undefined behaviors -- 


Nice!
My code, my responsibility, my business not yours.

that does not sound like an interface to me. So if python modules are 
importable everywhere, and mutable from everywhere, then python 
modules are merely addresses to a collection of global variables? And 
they're only interfaces superficially? So that leaves us with 
Python's current implementation of unofficial global variables 
implemented as puesdo- interfaces by module objects that are victims 
waiting to be violated. Interesting. IF IT WALKS LIKE A GLOBAL DUCK 
AND... 


Nice choice of words, violated, victims Really conductive to a
balanced unprejudiced thought process.

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


Re: To whoever hacked into my Database

2013-11-12 Thread Ned Batchelder
On Tuesday, November 12, 2013 1:31:32 AM UTC-5, ru...@yahoo.com wrote:
 On 11/11/2013 06:16 PM, Ned Batchelder wrote:
  Nikos has received a good deal of genuine advice.  He has also been
  genuinely difficult to help.
 
 Yes.  If he is too difficult to help without getting
 angry because he won't do what you (generic) tell him
 then perhaps a more constructive response is to stop
 trying to help him rather than join the lynch mob that
 is making the atmosphere here far worse (IMO) than
 Nikos alone could.

I absolutely agree with this. 

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


Re: To whoever hacked into my Database

2013-11-12 Thread Tim Chase
On 2013-11-11 22:24, ru...@yahoo.com wrote:
 And your suggestion is not necessarily best either: why a 1:M
 relationship? why not a M:M relationship?  There may be duplicate
 file downloads resulting in your suggestion being non-normalized. 

You think that, after rejecting the addition of *one* new table for
1:M relationships, he'd go for adding *two* new tables for an N:M
relationship?

 But I think he is being perfectly reasonable in rejecting a
 separate table if he feels it does not meet *his* needs (even if he
 is wrong in your opinion.) 

However, the needs that he *describes* call for at least one more
table, on pain of future problems, inter alia:

- non-atomic updates
- growth to an unknown number of files, exceeding the size of his one
  CHAR/VARCHAR field
- difficulty querying which files were used (including the inability
  to easily summarize/group by file)
- inability to maintain metadata for each file (a case for your N:M
  suggestion)

Knowing these things and Nikos' historical inability to debug issues,
it' worthwhile to get him to use a method that will result in less
pain.  Especially when you know from his description that his choices
*WILL* cause him future pain.

-tkc


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


Re: Creating a function for a directory

2013-11-12 Thread unknown
On Tue, 12 Nov 2013 11:24:02 +0100, Peter Otten wrote:

 unknown wrote:
 
 On Mon, 11 Nov 2013 14:26:46 -0800, Matt wrote:
 
 So I want to take the file, desktop/test.txt and write it to
 desktop/newfolder/test.txt. I tried the below script, and it gave
 me:
 IOError: [Errno 2] No such file or directory: 'desktop/%s.txt'. Any
 suggestions would be great.
 
 
 
 def firstdev(file):
 in_file = open(desktop/%s.txt) % file indata = in_file.read()
 out_file = open(desktop/newfolder/%s.txt, 'w') % file
 out_file.write(indata)
 out_file.close()
 in_file.close()
 
 firstdev(test)
 
 would it not be more efficient and less error prone to use the os
 module to copy the file rather than manually reading  re-writing it
 (unless of-
 course you intend to expand this in future to process the data first)?
 
 Hmm, I don't see a suitable function in os -- but there is
 
 shutil.copy()

that's what i get for posting on the fly without checking first but i 
think the principle holds.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyMyth: Global variables are evil... WRONG!

2013-11-12 Thread Tim Chase
On 2013-11-11 20:46, Rick Johnson wrote:
 Yes, and i agree. But you cannot hide everything. There
 will always be a need to share information.

You may not be able to (or want to) hide everything, but sharing
should at least happen over defined protocols (functions/methods).
Otherwise, you wander off into the weeds of hackery and
monkey-patching which makes maintaining the code a lot hairier.

-tkc


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


Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Steven D'Aprano
On Tue, 12 Nov 2013 08:01:19 +0100, Frank-Rene Schäfer wrote:

 the existence of a built-in function 'isimmutable' puts the concept of
 immutability some more into the spotlight.

That is an argument against the proposal, not in favour. The concept of 
immutability doesn't need to be in the spotlight. It is rather 
unimportant. I've been using Python for over 15 years, and have never 
missed an isimmutable function. Once, when I was just starting with 
Python, I thought I'd try writing one. I found it harder than I expected, 
and less useful, and soon gave up. And have never missed it yet.


 You might indeed implement some personal 'policy for copy/deepcopy'.
 But, how can you prevent the insertion of an object into the data tree
 which does not follow your copy/deepcopy convention?

I don't understand what this policy is supposed to be.


 As soon as you
 allow members of type 'tuple' you must either check recursively or only
 allow ints and strings as tuple members.

Why do you think you need to check at all? I think this is where we are 
talking past each other -- you seem to believe that testing for 
immutability is a critical piece of functionality which is missing from 
Python, as if lists had no way to query their length, or floats had no 
way to do multiplication. But that is not the case. Python has no 
isimmutable built-in function because, for the 20+ years that Python has 
existed, nobody who wanted it was willing to do the work to write it, and 
nobody willing to do the work thought it was important.

I believe that if you wish this PEP to go anywhere, you need to 
concentrate on two things:

1) demonstrating that checking for immutability is *necessary*

2) demonstrating that it is *possible*


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


Python and Android: PyImport_ImportModule always returns NULL

2013-11-12 Thread Dominik Weinhold

Hello all together,

I have  a python and android related issue. I hope that this is no 
problem because apart from stack overflow, where I also posted this 
question (but got no answer so far), I think a python mailing-list is 
the best place to post this question.


I am trying to use Python-Scripts in Android. So far a managed to get 
python as a shared library and linked it to my android project using 
Android.mk. I also created a file named wrapper.c which gets called from 
Java using jni and is used to call the python-script using the 
Python-C-Api. But when I try to open the script using 
PyImport_ImportModul, it always returns NULL.


First here is my Android.mk file which I put in the jni-folder of my 
Android project:


LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := luajit
LOCAL_SRC_FILES := libluajit.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_SHARED_LIBRARIES := luajit
LOCAL_SHARED_LIBRARIES += libcutils
LOCAL_LDLIBS := -llog
LOCAL_MODULE := wrapper
LOCAL_SRC_FILES := wrapper.c
LOCAL_EXPORT_C_INCLUDES := .
include $(BUILD_SHARED_LIBRARY)
This file does not cause any problems so far. wrapper.c is the c-file 
which is called from java using jni. This file uses the Python-C-Api to 
call a Python script. This is wrapper.c:


jstring
Java_com_example_pythonandroid_MainActivity_stringFromJNI(JNIEnv* env 
jobject thiz, jstring filename, jstring path) {

PyObject *modul, *funk, *ret;
char *erg;


const char *filenameCString = (*env)-GetStringUTFChars(env, 
filename, 0);

char *pathCString = (*env)-GetStringUTFChars(env, path, 0);
__android_log_print(ANDROID_LOG_INFO, CFilename, filenameCString);
__android_log_print(ANDROID_LOG_INFO, CPath, pathCString);
Py_Initialize();
PySys_SetPath(pathCString);

modul = PyImport_ImportModule(filenameCString);
if(modul!=NULL) {
funk = PyObject_GetAttrString(modul, helloPy);
ret = PyObject_CallObject(funk, NULL);
erg = PyString_AsString(ret);
__android_log_print(ANDROID_LOG_INFO, pyAnswer, erg);

Py_DECREF(ret);
Py_DECREF(funk);
Py_DECREF(modul);

Py_Finalize();
return (*env)-NewStringUTF(env, erg);
} else {
return (*env)-NewStringUTF(env, Error: Modul not found);
}
}

Filename and Path (set on the java-site) in this case are:

/data/data/com.example.pythonandroid/files/test.py
/data/data/com.example.pythonandroid/files
The file test.py was placed in the res/raw folder of the Android Project.

To check if they refer to the correct file, I printed the file 
/data/data/com.example.pythonandroid/files/test.py in wrapper.c and got 
the content of my python script. So everything seems to be alright on 
this end.


From the information I've read so far I understand that I have to set 
PySys_SetPath to the path where Python should look for modules. After 
that I can import them which PyImport_ImportModule. I also tried to set 
PySys_SetPath(.) even though it seems unrealistic that the actual path 
and the path of the script are the same. Anyway: it didn't work.


I hope I gave you all the information you need. Thanks in advance.

greetings
Dominik


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


Re: datetime question

2013-11-12 Thread Andy Lawton
Firstly , I should clarify I have no idea how to program python, I joined
this mailing list in anticipation of learning soon. And thought I'd have a
go playing around with your code and code given to you (worst possible
place to start, I'm sure)

But from the answers already given to you, this seems to work and as you
requested, in reality, this keeps your code to 1 line...

I'm sure this is wrong, and isn't what you want, but hey, Correct working
code doesn't seem to matter to you anyway...

(I think Europe/Kiev is Greece but I don't know)

from datetime import datetime, time, timedelta
import time
import pytz

def is_dst(zonename):
tz = pytz.timezone(zonename)
now = pytz.utc.localize(datetime.utcnow())
return now.astimezone(tz).dst() != timedelta(0)

def dst_greece():
if is_dst(Europe/Kiev) :
diff = 2
else:
diff = 3
return diff

lastvisit = (datetime.utcnow() +timedelta(hours=dst_greece())).strftime(
'%y-%m-%d %H:%M:%S' )


On 12 November 2013 10:15, Ferrous Cranus nikos.gr...@gmail.com wrote:

 Στις 8/11/2013 11:11 μμ, ο/η Νίκος Αλεξόπουλος έγραψε:

 Is there someway to write the following line even better with the

 ability to detect daylight saving time by itself so i don't have to
 alter the line manually when time changes?

 lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
 '%y-%m-%d %H:%M:%S' )# MySQL datetime format

 Thanks.



 Example:

 #check if date entered as intented, format it properly for MySQL
 lastvisit = datetime.strptime(lastvisit, '%d %m %Y').strftime('%Y-%m-%d')

 The above code gets the datetime string in a specific way and then convert
 it to another format. All happens in one line clear and simple.

 Now, in the following statement there shopuld be some way to check for
 daylight saving time so i would aboiut add +2 in winter or +3 for greek
 summer time.


 lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime( '%y-%m-%d
 %H:%M:%S' )  # MySQL datetime format

 I think + timedelta(hours=2) should be substituted with something else but
 i don't with what.
 --
 https://mail.python.org/mailman/listinfo/python-list

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


Re: To whoever hacked into my Database

2013-11-12 Thread Ian Kelly
On Tue, Nov 12, 2013 at 2:09 AM, Antoon Pardon
antoon.par...@rece.vub.ac.be wrote:
 So you are complaining about people being human. Yes that is
 how people tend to react when they continualy are frustrated
 by someone who refuses to show the slightest cooperation.
 So no rejecting such responses, particullarly by the person
 who caused them is not right. It is defelecting the blame from
 the primal cause.

As you say you're a human, not a sheep, so stop pointing at the
behavior of others to justify your own.  But he started it wasn't an
excuse in kindergarten, and it still isn't one now.  Somebody has to
accept the responsibility to walk away and break the positive feedback
loop, or it will never end.  And I can't see Nikos being the one to do
that.

 That is correct but is expecting too much from people in general.
 Expecting from frustrated people to act rational and constructive
 is just a recipe for your own frustrations.

In my experience, conduct follows from self esteem and self worth, and
those things follow in turn from the respect and expectations of
others.  If I expect others to act like animals, then I disrespect
them, and so why should they behave any differently toward me or in my
presence?  By expecting others to be rational and mature I show my
respect for them, and so perhaps they will see fit to behave in a way
to maintain that respect.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Ferrous Cranus

Στις 12/11/2013 2:47 μμ, ο/η Andy Lawton έγραψε:

Firstly , I should clarify I have no idea how to program python, I
joined this mailing list in anticipation of learning soon. And
thought I'd have a go playing around with your code and code given to
you (worst possible place to start, I'm sure)

But from the answers already given to you, this seems to work and as you
requested, in reality, this keeps your code to 1 line...

I'm sure this is wrong, and isn't what you want, but hey, Correct
working code doesn't seem to matter to you anyway...

(I think Europe/Kiev is Greece but I don't know)

from datetime import datetime, time, timedelta
import time
import pytz

def is_dst(zonename):
 tz = pytz.timezone(zonename)
 now = pytz.utc.localize(datetime.utcnow())
 return now.astimezone(tz).dst() != timedelta(0)

def dst_greece():
 if is_dst(Europe/Kiev) :
 diff = 2
 else:
 diff = 3
 return diff

lastvisit = (datetime.utcnow() +timedelta(hours=dst_greece())).strftime(
'%y-%m-%d %H:%M:%S' )


On 12 November 2013 10:15, Ferrous Cranus nikos.gr...@gmail.com
mailto:nikos.gr...@gmail.com wrote:

Στις 8/11/2013 11:11 μμ, ο/η Νίκος Αλεξόπουλος έγραψε:

Is there someway to write the following line even better with the

ability to detect daylight saving time by itself so i don't have to
alter the line manually when time changes?

lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
'%y-%m-%d %H:%M:%S' )# MySQL datetime format

Thanks.



Example:

#check if date entered as intented, format it properly for MySQL
lastvisit = datetime.strptime(lastvisit, '%d %m
%Y').strftime('%Y-%m-%d')

The above code gets the datetime string in a specific way and then
convert it to another format. All happens in one line clear and simple.

Now, in the following statement there shopuld be some way to check
for daylight saving time so i would aboiut add +2 in winter or +3
for greek summer time.


lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
'%y-%m-%d %H:%M:%S' )  # MySQL datetime format

I think + timedelta(hours=2) should be substituted with something
else but i don't with what.
--
https://mail.python.org/__mailman/listinfo/python-list
https://mail.python.org/mailman/listinfo/python-list





this requires a function to be declared while i just want just an 
argument inside timedelta( ) that will automatically detect DST or not.


No function declaration but instead something like:
lastvisit = ( datetime.utcnow() + timedelta( some_arg_here_that_can 
detect greece's_DST_or_not) ).strftime) '%y-%m-%d %H:%M:%S' ) 
   # MySQL datetime format




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


Re: To whoever hacked into my Database

2013-11-12 Thread Ferrous Cranus

Στις 11/11/2013 11:36 πμ, ο/η Νίκος Αλεξόπουλος έγραψε:

Στις 6/11/2013 5:25 μμ, ο/η Νίκος Γκρ33κ έγραψε:

Okey let the hacker try again to mess with my database!!!

He is done it twice, lets see if he will make it again!

I'am waiting!


I can't believe your ignorance. You're actually telling a huge group of
developers from all over the globe that your site is impenetrable. Do
you know how ridiculous you sound? Have you stopped and thought that
maybe people have better things to do than try to hack your stupid circa
1990 website? My three year old could have modified your database. It
doesn't take a pro to take down your 'security'. Have you not read up on
anything these people have suggested? Cross Site Scripting? SQL
Injection? Digital Piracy? Private User Information? No.. you haven't.
That's why your code is starting to look like this:
if not '..' in page and not page == '/etc/passwd' and
os.path.isfile(page) and os.path.exists('/cgi-bin' + page) and cookieID
== 'some_secret' and host == 'superhost.gr' and
hacker_is_not_being_mean_today:
load_site()

load_private_user_phone_numbers_and_then_post_a_screenshot_for_everyone_to_see()

else:
play_pre_millenium_music_and_load_lots_of_gifs()
wait___go_back_and_load_pirated_music_and_gifs_from_1995_anyway(extra_sauce=True)

You can't sue me for posting the code to your site, there was no copyright.
I guess my whole point is, if someone really cared I'm sure they could
get into your site. They could get into a lot of sites that were created
by people way smarter than you. Ever heard of apache exploits? cpanel
exploits? for that matter..python exploits? Some of this is beyond your
control. Actually, all of this is beyond your personal control, you lack
the capability. What I meant to say is that you could not possibly fix
all of this even if you were a better python programmer. Be glad 'she'
wasn't mean.

==

Somebody this morning sent me an email as nikos.su...@gmail.com sayign
the above.
My code is not like you provided you ignorant.

# is it a python file or an html template?
if page and page in os.listdir( cgi_path ):
 pyvalid = True
elif os.path.isfile( file ):
 page = file.replace( path, '' )
 htmlvalid = True
else:
 file = 'forbidden'


if 'forbidden' in file:
 print( '''h2font color=redΔεν επιτρέπεται η απευθείας πρόσβαση
στο script παρά μόνον μέσω της αρχικής σελίδας!Ανακατεύθυνση σε
5...''' )
 print( '''meta http-equiv=REFRESH
content=5;URL=http://superhost.gr;''' )
 sys.exit(0)


if cookieID != 'wont_say' and ( htmlvalid or pyvalid ) and re.search(
r'(amazon|google|proxy|cloud|reverse|fetch|msn|who|spider|crawl|ping)',
host ) is None:
 # do database insertion here


Tell the mighty female hacker to polish her nails, do her hair and fix a
good meal.

She is incompetent just like yourself.

These all is just an excuse of not being able to mess with my script
again, because is she could she would.



Numerous attempts so far but no break through and database mess 2 days now.

Okey i think its safe to say that manipulation of databases through my 
script's variables cannot happen again.

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


Re: Creating a function for a directory

2013-11-12 Thread Neil Cerutti
On 2013-11-12, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Using os.path.exists before opening a file is, for the most
 part, a waste of time.

I use it in conjuction with file creation times to check that I
didn't forget to update/create one of the data files a process
might need.

Since I have to create the data file manually, race conditions
seem unlikely.

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


Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Robert Kern

On 2013-11-12 11:14, Steven D'Aprano wrote:

On Tue, 12 Nov 2013 18:12:43 +1100, Chris Angelico wrote:


def isimmutable(x):
 try:
 hash(x)
 return True
 except TypeError:
 return False


I'm afraid that doesn't test for immutability. It tests for hashability,
which is different.


I am going to nitpick below for nitpicking's sake, but I agree with this.


No well-behaved mutable object can be hashable, but that's not to say
that badly-behaved mutable objects won't be hashable.


That's not quite true. A well-behaved mutable may be (well-behaved) hashable as 
long as the allowed mutations do not affect the equality comparison. For 
example, in Python 2, all new classes are mutable by default, but they are also 
well-behaved hashable by default because their equality comparison is identity 
comparison. None of the mutations affect object identity, so the hash based on 
identity remains well-behaved.



And every immutable
object should be hashable, but that's not to say that some immutable
objects might choose, for their own reasons, not to be hashable.


I would also dispute this. A tuple itself is immutable, but it may not be 
hashable because one of its contained objects is unhashable (whether due to 
mutability or something else).



So your function is subject to both false negatives and false positives.


Agreed.

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

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


Re: datetime question

2013-11-12 Thread Joel Goldstick
On Tue, Nov 12, 2013 at 8:32 AM, Ferrous Cranus nikos.gr...@gmail.com wrote:
 Στις 12/11/2013 2:47 μμ, ο/η Andy Lawton έγραψε:

 Firstly , I should clarify I have no idea how to program python, I
 joined this mailing list in anticipation of learning soon. And
 thought I'd have a go playing around with your code and code given to
 you (worst possible place to start, I'm sure)

 But from the answers already given to you, this seems to work and as you
 requested, in reality, this keeps your code to 1 line...

 I'm sure this is wrong, and isn't what you want, but hey, Correct
 working code doesn't seem to matter to you anyway...

 (I think Europe/Kiev is Greece but I don't know)

 from datetime import datetime, time, timedelta
 import time
 import pytz

 def is_dst(zonename):
  tz = pytz.timezone(zonename)
  now = pytz.utc.localize(datetime.utcnow())
  return now.astimezone(tz).dst() != timedelta(0)

 def dst_greece():
  if is_dst(Europe/Kiev) :
  diff = 2
  else:
  diff = 3
  return diff

 lastvisit = (datetime.utcnow() +timedelta(hours=dst_greece())).strftime(
 '%y-%m-%d %H:%M:%S' )


 On 12 November 2013 10:15, Ferrous Cranus nikos.gr...@gmail.com
 mailto:nikos.gr...@gmail.com wrote:

 Στις 8/11/2013 11:11 μμ, ο/η Νίκος Αλεξόπουλος έγραψε:

 Is there someway to write the following line even better with the

 ability to detect daylight saving time by itself so i don't have
 to
 alter the line manually when time changes?

 lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
 '%y-%m-%d %H:%M:%S' )# MySQL datetime format

 Thanks.



 Example:

 #check if date entered as intented, format it properly for MySQL
 lastvisit = datetime.strptime(lastvisit, '%d %m
 %Y').strftime('%Y-%m-%d')

 The above code gets the datetime string in a specific way and then
 convert it to another format. All happens in one line clear and
 simple.

 Now, in the following statement there shopuld be some way to check
 for daylight saving time so i would aboiut add +2 in winter or +3
 for greek summer time.


 lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
 '%y-%m-%d %H:%M:%S' )  # MySQL datetime format

 I think + timedelta(hours=2) should be substituted with something
 else but i don't with what.
 --
 https://mail.python.org/__mailman/listinfo/python-list
 https://mail.python.org/mailman/listinfo/python-list




 this requires a function to be declared while i just want just an argument
 inside timedelta( ) that will automatically detect DST or not.

 No function declaration but instead something like:
 lastvisit = ( datetime.utcnow() + timedelta( some_arg_here_that_can detect
 greece's_DST_or_not) ).strftime) '%y-%m-%d %H:%M:%S' )# MySQL
 datetime format



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

I think that is a great solution.  What would happen if you just did this:
lastvisit2 = (datetime.now()).strftime('%y-%m-%d %H:%M:%S' )

Why don't you try it out and see what you find?

(PS, this was pointed out to me by a pro, so I did a little reading in
the python docs and took Andy's excellent code and added a couple of
lines to test.)

I switched to my local timezone US/Eastern to test. My machine is
running Ubuntu.  It seems to know that it is in the Eastern US.  If
your server knows where it lives, then this should work for you also.
If it is set to a different timezone, I'm not sure I could help you,
but I'm sure someone could.  You even might ask your host if this is
possible.

--
#! /usr/bin/env python

from datetime import datetime, time, timedelta
import time
import pytz

def is_dst(zonename):
 tz = pytz.timezone(zonename)
 now = pytz.utc.localize(datetime.utcnow())
 return now.astimezone(tz).dst() != timedelta(0)

def dst_greece():
 #if is_dst(Europe/Kiev) :
 if is_dst(US/Eastern) :
 diff = -6
 else:
 diff = -5
 return diff

lastvisit = (datetime.utcnow()
+timedelta(hours=dst_greece())).strftime('%y-%m-%d %H:%M:%S' )

lastvisit2 = (datetime.now()).strftime('%y-%m-%d %H:%M:%S' )

print lastvisit
print lastvisit2

--


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


Re: PyMyth: Global variables are evil... WRONG!

2013-11-12 Thread jongiddy
On Tuesday, November 12, 2013 2:06:09 AM UTC, Rick Johnson wrote:

 
 
 
  Justifying Global Variables:
 
 
 
 Globals are justified when they are used to communicate
 
 information between scopes that otherwise were meant to be
 
 mutually exclusive. One good example would be package sub-
 
 modules.
 

Can you please give an example where having a module provide a global variable 
would work better than any of:
1. providing a module function to change the operation of my module
2. providing a class with a method to change the operation of an instance
3. providing an additional parameter to module functions / instance methods to 
change operation
4. providing additional module functions / instance methods to perform 
different operations
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Ferrous Cranus

Στις 12/11/2013 4:03 μμ, ο/η Joel Goldstick έγραψε:

On Tue, Nov 12, 2013 at 8:32 AM, Ferrous Cranus nikos.gr...@gmail.com wrote:

Στις 12/11/2013 2:47 μμ, ο/η Andy Lawton έγραψε:


Firstly , I should clarify I have no idea how to program python, I
joined this mailing list in anticipation of learning soon. And
thought I'd have a go playing around with your code and code given to
you (worst possible place to start, I'm sure)

But from the answers already given to you, this seems to work and as you
requested, in reality, this keeps your code to 1 line...

I'm sure this is wrong, and isn't what you want, but hey, Correct
working code doesn't seem to matter to you anyway...

(I think Europe/Kiev is Greece but I don't know)

from datetime import datetime, time, timedelta
import time
import pytz

def is_dst(zonename):
  tz = pytz.timezone(zonename)
  now = pytz.utc.localize(datetime.utcnow())
  return now.astimezone(tz).dst() != timedelta(0)

def dst_greece():
  if is_dst(Europe/Kiev) :
  diff = 2
  else:
  diff = 3
  return diff

lastvisit = (datetime.utcnow() +timedelta(hours=dst_greece())).strftime(
'%y-%m-%d %H:%M:%S' )


On 12 November 2013 10:15, Ferrous Cranus nikos.gr...@gmail.com
mailto:nikos.gr...@gmail.com wrote:

 Στις 8/11/2013 11:11 μμ, ο/η Νίκος Αλεξόπουλος έγραψε:

 Is there someway to write the following line even better with the

 ability to detect daylight saving time by itself so i don't have
to
 alter the line manually when time changes?

 lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
 '%y-%m-%d %H:%M:%S' )# MySQL datetime format

 Thanks.



 Example:

 #check if date entered as intented, format it properly for MySQL
 lastvisit = datetime.strptime(lastvisit, '%d %m
 %Y').strftime('%Y-%m-%d')

 The above code gets the datetime string in a specific way and then
 convert it to another format. All happens in one line clear and
simple.

 Now, in the following statement there shopuld be some way to check
 for daylight saving time so i would aboiut add +2 in winter or +3
 for greek summer time.


 lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
 '%y-%m-%d %H:%M:%S' )  # MySQL datetime format

 I think + timedelta(hours=2) should be substituted with something
 else but i don't with what.
 --
 https://mail.python.org/__mailman/listinfo/python-list
 https://mail.python.org/mailman/listinfo/python-list





this requires a function to be declared while i just want just an argument
inside timedelta( ) that will automatically detect DST or not.

No function declaration but instead something like:
lastvisit = ( datetime.utcnow() + timedelta( some_arg_here_that_can detect
greece's_DST_or_not) ).strftime) '%y-%m-%d %H:%M:%S' )# MySQL
datetime format



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


I think that is a great solution.  What would happen if you just did this:
lastvisit2 = (datetime.now()).strftime('%y-%m-%d %H:%M:%S' )

Why don't you try it out and see what you find?

(PS, this was pointed out to me by a pro, so I did a little reading in
the python docs and took Andy's excellent code and added a couple of
lines to test.)

I switched to my local timezone US/Eastern to test. My machine is
running Ubuntu.  It seems to know that it is in the Eastern US.  If
your server knows where it lives, then this should work for you also.
If it is set to a different timezone, I'm not sure I could help you,
but I'm sure someone could.  You even might ask your host if this is
possible.

--
#! /usr/bin/env python

from datetime import datetime, time, timedelta
import time
import pytz

def is_dst(zonename):
  tz = pytz.timezone(zonename)
  now = pytz.utc.localize(datetime.utcnow())
  return now.astimezone(tz).dst() != timedelta(0)

def dst_greece():
  #if is_dst(Europe/Kiev) :
  if is_dst(US/Eastern) :
  diff = -6
  else:
  diff = -5
  return diff

lastvisit = (datetime.utcnow()
+timedelta(hours=dst_greece())).strftime('%y-%m-%d %H:%M:%S' )

lastvisit2 = (datetime.now()).strftime('%y-%m-%d %H:%M:%S' )

print lastvisit
print lastvisit2

--





Joel i must thank you for your help.

I cannot believe it was so simple.

lastvisit = ( datetime.now() ).strftime('%y-%m-%d %H:%M:%S')			# MySQL 
datetime format



Tnhe server is self aware of its location so why use utcnow() + 
timedelte( some_digit_here ) when you can just use just now()


Great solution, no need for function declaration and importing of new 
pytz modules.


Simple and straightforward, Thank you!
--
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Roy Smith
In article l5sc04$3vd$1...@reader1.panix.com,
 Grant Edwards invalid@invalid.invalid wrote:

 On 2013-11-11, Mark Lawrence breamore...@yahoo.co.uk wrote:
  On 11/11/2013 23:21, mm0fmf wrote:
  On 11/11/2013 19:39, Ethan Furman wrote:
  On 11/11/2013 11:19 AM, Denis McMahon wrote:
  On Mon, 11 Nov 2013 11:57:36 +0200, ?? ?? 
  wrote:
 
  lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
  '%y-%m-%d %H:%M:%S' )# MySQL datetime format
 
  Someone has an idea what to add to this line to automatically adjust
  itself if DST happens?
 
  Yes, but the scarcity of universal whitespace is preventing me from
  posting it.
 
  Boy, are you in luck!  I just happen to have a whole heap of marked down
  ascii white-space at bargain basement prices!
 
  Is that metric or imperial whitespace?
 
  You need metric whitespace for programs written in Europe.
 
  Except for the UK, our multi-national approach means that both imperial 
  and metric whitespace are acceptable.
 
 Don't forget that there are also some differences between American and
 Imperial whitespace.  Since it's ASCII whitespace, you should probably
 assume American...

And don't assume that the whitespace you find in a red state is the same 
as you'll find in a blue state.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyMyth: Global variables are evil... WRONG!

2013-11-12 Thread Alister
On Mon, 11 Nov 2013 18:06:09 -0800, Rick Johnson wrote:

 
 In this thread, i want to get to the bottom of this whole
 global-phobia thing once and for all, and hopefully help you folks
 understand that globals are not all that bad -- when DESIGNED and USED
 correctly that is!

it is the final part of that statement that is important

As a generality Avoid Globals is not a bad rule.
there may be some occasions when breaking this rule may be acceptable but 
it requires great experience  detailed knowledge to know when this is 
the right thing to do.

As an analogy music has may general rules that musicians are wise to 
follow.
Some pieces of music that break these rules are great because they have 
broken the rules but most are not. those that are great are great because 
the musician in question understands the reasons for the rules  how 
breaking them will affect the end product, the ones that are bad are 
because the musician does not know enough about music to even know the 
rule exists.





-- 
Immutability, Three Rules of:
(1)  If a tarpaulin can flap, it will.
(2)  If a small boy can get dirty, he will.
(3)  If a teenager can go out, he will.
(3a) If a teenager cant go out, he will. :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Implementing a multivibrator function with python

2013-11-12 Thread JL
I am actually running python on raspberry pi. The trigger event is a 
button-press.

On Monday, November 11, 2013 6:56:03 PM UTC+8, Dave Angel wrote:
 On Mon, 11 Nov 2013 01:41:58 -0800 (PST), JL lightai...@gmail.com 
 
 wrote:
 
  - If the event happens again before the 5secs expire, the high 
 
 duration will be extended by another 5 secs. This works like a 
 
 retriggerable multivibrator for those who are into electronics.
 
 
 
 More precisely a retriggerable monostable multivibrator.
 
 
 
 The question makes little sense unless you're running in an event 
 
 driven environment, such as a gui. Name the environment and somebody 
 
 can probably help.
 
 
 
 -- 
 
 DaveA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 1:12 AM, Ferrous Cranus nikos.gr...@gmail.com wrote:
 Joel i must thank you for your help.

 I cannot believe it was so simple.

 Tnhe server is self aware of its location so why use utcnow() + timedelte(
 some_digit_here ) when you can just use just now()

Did you ever go and look at the docs, like you were advised to?

Next time you have a problem, go read the docs. You never know, you
might discover something!

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


Re: PyMyth: Global variables are evil... WRONG!

2013-11-12 Thread Rick Johnson
On Tuesday, November 12, 2013 8:12:10 AM UTC-6, jongiddy wrote:

 Can you please give an example where having a module
 provide a global variable would work better than any of:
 [snip]

Well my point is that the attributes of any Python module
are emulating globals already. The fact that we have to
mutate them via a psuedo interface makes us falsely
believe we are using an interface -- but we aren't!

 PYTHON MADE ACCESSING GLOBAL VARIABLES MORE DIFFICULT!

As example. I could import the math module and start
fiddling with attributes. Let's say for example i can change
the value of math.pi. Most people would probably say what's
the problem with that?, here, let me show you.

# mod1.py
print mod1.py
import math
math.pi = tasty

# mod2.py
print mod2.py
import math
print ' value of math.pi is:', math.pi
radius = 10
math.pi * radius

#modmain.py
import mod1
import mod2
print dir(mod1)
print dir(mod2)

When you run modmain.py you will see that not only have we
changed the global variable pi to a string, but thanks to
a dumb overloading of the multiply operator, python will
happily give use the wrong answer -- but that's another
problem, let's stay focused on the global problem for now!

When i type math.pi, i feel as though i'm accessing an
interface, BUT I'M NOT! If i was indeed accessing a TRUE
interface, the interface would have thrown a Type error for
attempting to assign a value of type string to what should
only be a float. The interface would have protected it's
internal data from corruption, but it didn't.

  BECAUSE IT'S NOT AN INTERFACE!

It's just a dumb namespace with no exposed hooks to control
it's underlying behavior.

  MY POINT IS:

Python designers act like globals are SO evil, but then they
give us modules which are containers for global variables,
and now the globals contained within those modules are
wolves in sheep's clothing. Are they just trying to fool
themselves, or fool us?

  FOOD FOR THOUGHT:

What's worse? A wolf? Or a wolf in sheep's clothing?
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: Python Meeting Düsseldorf - 19.11.2013

2013-11-12 Thread eGenix Team: M.-A. Lemburg
[This announcement is in German since it targets a local user group
 meeting in Düsseldorf, Germany]


ANKÜNDIGUNG

 Python Meeting Düsseldorf

 http://pyddf.de/

   Ein Treffen von Python Enthusiasten und Interessierten
in ungezwungener Atmosphäre.

  Dienstag, 19.11.2013, 18:00 Uhr
  Raum 1, 2.OG im Bürgerhaus Stadtteilzentrum Bilk
Düsseldorfer Arcaden, Bachstr. 145, 40217 Düsseldorf

Diese Nachricht ist auch online verfügbar:
http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2013-11-19


NEUIGKEITEN

 * Bereits angemeldete Vorträge:

   Jan Ulrich Hasecke
   Was ich beim Schreiben eines Handbuches über Sphinx über
Sphinx lernte

   Charlie Clark
   Openpyxl: Sprint  Danach

   Marc-Andre Lemburg
   Home-Automation mit Kivy, Mosquitto und Tellstick

   Charlie Clark
   Paralleles Browser-Testing mit Sauce-Labs

 * Neuer Veranstaltungsraum:

   Wir treffen uns im Bürgerhaus in den Düsseldorfer Arcaden.
   Da beim letzten Mal einige Teilnehmer Schwierigkeiten hatten,
   den Raum zu finden, hier eine kurze Beschreibung:

   Das Bürgerhaus teilt sich den Eingang mit dem Schwimmbad
   und befindet sich an der Seite der Tiefgarageneinfahrt der
   Düsseldorfer Arcaden.

   Über dem Eingang steht ein großes “Schwimm’'in Bilk”
   Logo. Hinter der Tür direkt links zu den zwei Aufzügen,
   dann in den 2. Stock hochfahren. Der Eingang zum Raum 1
   liegt direkt links, wenn man aus dem Aufzug kommt.

   Google Street View: http://bit.ly/11sCfiw


EINLEITUNG

Das Python Meeting Düsseldorf ist eine regelmäßige Veranstaltung in
Düsseldorf, die sich an Python Begeisterte aus der Region wendet:

 * http://pyddf.de/

Einen guten Überblick über die Vorträge bietet unser YouTube-Kanal,
auf dem wir die Vorträge nach den Meetings veröffentlichen:

 * http://www.youtube.com/pyddf/

Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld,
in Zusammenarbeit mit Clark Consulting  Research, Düsseldorf:

 * http://www.egenix.com/
 * http://www.clark-consulting.eu/


PROGRAMM

Das Python Meeting Düsseldorf nutzt eine Mischung aus Open Space
und Lightning Talks, wobei die Gewitter bei uns auch schon mal
20 Minuten dauern können ;-).

Lightning Talks können vorher angemeldet werden, oder auch
spontan während des Treffens eingebracht werden. Ein Beamer mit
XGA Auflösung steht zur Verfügung. Folien bitte als PDF auf USB
Stick mitbringen.

Lightning Talk Anmeldung bitte formlos per EMail an i...@pyddf.de


KOSTENBETEILIGUNG

Das Python Meeting Düsseldorf wird von Python Nutzern für Python
Nutzer veranstaltet. Um die Kosten zumindest teilweise zu
refinanzieren, bitten wir die Teilnehmer um einen Beitrag
in Höhe von EUR 10,00 inkl. 19% Mwst, Schüler und Studenten
zahlen EUR 5,00 inkl. 19% Mwst.

Wir möchten alle Teilnehmer bitten, den Betrag in bar mitzubringen.


ANMELDUNG

Da wir nur für ca. 20 Personen Sitzplätze haben, möchten wir
bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung
eingegangen. Es erleichtert uns allerdings die Planung.

Meeting Anmeldung bitte formlos per EMail an i...@pyddf.de


WEITERE INFORMATIONEN

Weitere Informationen finden Sie auf der Webseite des Meetings:

http://pyddf.de/

Mit freundlichen Grüßen,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 12 2013)
 Python Projects, Consulting and Support ...   http://www.egenix.com/
 mxODBC.Zope/Plone.Database.Adapter ...   http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

2013-11-19: Python Meeting Duesseldorf ...  7 days to go

: Try our mxODBC.Connect Python Database Interface for free ! ::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyMyth: Global variables are evil... WRONG!

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 1:32 AM, Alister alister.w...@ntlworld.com wrote:
 As an analogy music has may general rules that musicians are wise to
 follow.
 Some pieces of music that break these rules are great because they have
 broken the rules but most are not. those that are great are great because
 the musician in question understands the reasons for the rules  how
 breaking them will affect the end product, the ones that are bad are
 because the musician does not know enough about music to even know the
 rule exists.

Agreed. Pieces of music that violate the rules arbitrarily are just
annoying to try to play (and nearly impossible for the church to
follow), but when you find those really brilliant pieces that do
something special (Sir Arthur Sullivan, I'm looking at you -
especially having just been reading the booklet that came with the new
Beauty Stone recording), it's magnificent.

Global variables basically don't exist in Python. You have per-module
state. And if you start monkey-patching, you're fiddling with someone
else's module. It's all fun and games till someone loses a function...

sys.stdout.write=None

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


Re: datetime question

2013-11-12 Thread Ferrous Cranus

Στις 12/11/2013 4:57 μμ, ο/η Chris Angelico έγραψε:

On Wed, Nov 13, 2013 at 1:12 AM, Ferrous Cranus nikos.gr...@gmail.com wrote:

Joel i must thank you for your help.

I cannot believe it was so simple.

Tnhe server is self aware of its location so why use utcnow() + timedelte(
some_digit_here ) when you can just use just now()


Did you ever go and look at the docs, like you were advised to?

Next time you have a problem, go read the docs. You never know, you
might discover something!

ChrisA




But what of the server was in California and i live in Greece?

How would datetime.now() work then?

now() would return the time fo the server not my local time, so if i 
change servers and the server isn't located to the same timezone as i'am 
locally, wouldn't that raise a problem?

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


Re: PyMyth: Global variables are evil... WRONG!

2013-11-12 Thread jongiddy
On Tuesday, November 12, 2013 3:05:25 PM UTC, Rick Johnson wrote:
 
 
 
 When i type math.pi, i feel as though i'm accessing an
 
 interface, BUT I'M NOT! 

I'm not sure where you get the feeling you're accessing an interface. If I 
typed this, I would feel like I was trying to change a fundamental constant.

You have just demonstrated that going into other modules and changing their 
attributes (whether they are variables, functions or classes) is generally a 
BAD idea, and I don't think I've ever seen anyone recommend doing this, except 
possibly as a workaround or for debugging purposes.

On the other hand, you initially suggested that modifying globals contained 
within namespaces (i.e. modules) is a good way to communicate between modules. 
That is, you suggested in your initial post that going into other modules and 
changing their attributes is a GOOD idea.

This inconsistency is why I was asking for a good example (i.e. a realistic 
example where the use of global variables provides the best solution).

Just because a tool allows you to do something does not make it a good idea. 
Try this paraphrase of your last post: Ladder designers act like standing on 
the top rung is SO evil, but then they give us ladders with a top rung, Are 
they just trying to fool themselves, or fool us? 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Conditional breakpoints in ceval.c

2013-11-12 Thread Demian Brecht
On Sat, Nov 9, 2013 at 5:33 AM,  python-list-requ...@python.org wrote:
 I don't know how to use gdb the way you want, but it sounds like you are on a 
 fascinating journey of discovery.  What are you trying to learn?  Perhaps we 
 can talk about how the interpreter works.

Apologies for not getting to this sooner, I took a much needed short
hiatus from touching all things computers over the long weekend.

A little backstory to how I got to this sticking point:

I decided to write a series of blog posts about the lesser-known areas
of the Python stdlib (I was considering doing a lightning talk about
one or two of them). First stop was abc's. When digging into that, I
realized that the implementation of abcs is a bit different than other
modules in the stdlib: It's only partially implemented in Python.

After digging into that more and figuring out how that was all
implemented in C, I also found that, while I understood how to use
metaclasses, I didn't quite understand how the interpreter used
metaclasses to build new classes (I had read the docs, but felt that I
couldn't explain it to my grandmother and therefore, a blog post on
metaclasses likely would only be surface level and wouldn't include
any information outside of what's readily available through the docs).

At that point, I had spent quite a bit of time grep'ing and grok'ing
various parts of the interpreter code. I felt there /had/ to be a be a
more efficient way to see what's going on for a particular code block.
Further digging pointed me to compile/dis to get the bytecode
generated by code blocks. This then led me to ceval.c, setting
breakpoints to step through and see what actually happens with the
code. This is where I ran into a bit of a wall due to my lack of
practice with gdb.

What I'm trying to do is essentially figure out a way to break into
the interpreter code at arbitrary points in my Python code so I can
step through exactly what's going on (which would be tremendously
useful IMO). I think what I lack is a fundamental understanding of how
to access attributes of the various Python object types at the
interpreter level. For example, if I want to break on the assignment
foo = 'bar', then I want to look for something to the effect of
(int)(strcmp(*(PyTuple_GetItem((consts), (oparg))-[??]), bar) == 0.


As an aside, this has definitely been one of the more interesting digs
that I've taken at Python and has been quite enjoyable and fulfilling
(my /god/ I'm a nerd ;)). You never /can/ really push the boundaries
with your tools without wholly understanding them.

-- 
Demian Brecht
http://demianbrecht.github.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Conditional breakpoints in ceval.c

2013-11-12 Thread Tim Golden
On 12/11/2013 15:40, Demian Brecht wrote:
 On Sat, Nov 9, 2013 at 5:33 AM,  python-list-requ...@python.org wrote:
 I don't know how to use gdb the way you want, but it sounds like you are on 
 a fascinating journey of discovery.  What are you trying to learn?  Perhaps 
 we can talk about how the interpreter works.
 
 Apologies for not getting to this sooner, I took a much needed short
 hiatus from touching all things computers over the long weekend.
 
 A little backstory to how I got to this sticking point:
 
 I decided to write a series of blog posts about the lesser-known areas
 of the Python stdlib (I was considering doing a lightning talk about
 one or two of them). First stop was abc's. When digging into that, I
 realized that the implementation of abcs is a bit different than other
 modules in the stdlib: It's only partially implemented in Python.
 
 After digging into that more and figuring out how that was all
 implemented in C, I also found that, while I understood how to use
 metaclasses, I didn't quite understand how the interpreter used
 metaclasses to build new classes (I had read the docs, but felt that I
 couldn't explain it to my grandmother and therefore, a blog post on
 metaclasses likely would only be surface level and wouldn't include
 any information outside of what's readily available through the docs).
 
 At that point, I had spent quite a bit of time grep'ing and grok'ing
 various parts of the interpreter code. I felt there /had/ to be a be a
 more efficient way to see what's going on for a particular code block.
 Further digging pointed me to compile/dis to get the bytecode
 generated by code blocks. This then led me to ceval.c, setting
 breakpoints to step through and see what actually happens with the
 code. This is where I ran into a bit of a wall due to my lack of
 practice with gdb.

You may well have seem them but, in case you haven't, look at Eli
Bendersky's occasional blog series:

http://eli.thegreenplace.net/category/programming/python/python-internals/

(Not answering your current query but hopefully useful anyway).

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


Re: datetime question

2013-11-12 Thread Tim Chase
On 2013-11-12 17:24, Ferrous Cranus wrote:
 But what of the server was in California and i live in Greece?
 
 How would datetime.now() work then?

Best practices say to move the value from local time to UTC as soon
as possible, then store/use the UTC time internally for all
operations.  Only when it's about to be presented to the user should
you convert it back to local time if you need to.

-tkc



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


Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Duncan Booth
=?UTF-8?Q?Frank=2DRene_Sch=C3=A4fer?= fsch...@gmail.com wrote:

 The ImmutableNester special class type would be a feature to help
 checks to avoid recursion. Objects of classes derived from
 ImmutableNester have no mutable access functions and allow insertion
 of members only at construction time. At construction time it checks
 whether all entered elements are immutable in the above sense.
 

How does this help anything? If the objects are all immutable the object 
cannot contain any recursive references.

If you cannot see this think about tuples: a tuple containing immutable 
objects including other tuples can never contain a reference to itself 
because by definition the tuple did not exist at the point where the 
elements it contains were constructed.

Python already relies on the non-recursive nature of nested tuples when 
handling exceptions: The expression in the 'except' clause is compatible 
with an exception if it is the class or a base class of the exception 
object or a tuple containing an item compatible with the exception.

If you try using something like a list in the exception specification you 
get a TypeError; only tuples and exception classes (subclasses of 
BaseException) are permitted. This means the structure can be as deeply 
nested as you wish, but can never be recursive and no checks against 
recursion need to be implemented.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Highest performance [benchmarked] HTTP microframework?

2013-11-12 Thread Alec Taylor
E.g.: using Cython

I am currently using Bottle, and it's fine; but provides much more than I need.

Investigating rewriting in C++; perhaps using restcgi. Can give that
restcgi a bit of a rewrite, removing the boost dependency and
replacing it with a C++11 dependency.

However given the lack of a neat ORM in C++ with a large variety of
backends (like SQLalchemy has); I would be leveraging boost::Python or
similar.

So maybe I should give Python another chance? - What's the highest
performance Python HTTP microframework capable of routing with
decorators?

Thanks for all suggestions,

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


Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread random832
On Tue, Nov 12, 2013, at 4:39, Frank-Rene Schäfer wrote:
  All you've done is proven that you can subvert things. By fiddling
  with __hash__, __eq__, and so on, you can make sets and dicts behave
  very oddly. Means nothing.
 
 To the contrary, it means everything about what 'isimmutable' could
 contribute: security against advert or inadvert insertion of mutable
 objects.

If an object can lie about its hashability, it can lie to your function
too... unless you don't intend to provide a way for a _genuinely_
immutable class to say so.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Ferrous Cranus

Στις 12/11/2013 5:54 μμ, ο/η Tim Chase έγραψε:

On 2013-11-12 17:24, Ferrous Cranus wrote:

But what of the server was in California and i live in Greece?

How would datetime.now() work then?


Best practices say to move the value from local time to UTC as soon
as possible, then store/use the UTC time internally for all
operations.  Only when it's about to be presented to the user should
you convert it back to local time if you need to.

-tkc






or perhaps by confiruing the timezone of the server to use Greece's 
TimeZone by issuing a linux command?

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


Re: Implementing a multivibrator function with python

2013-11-12 Thread unknown
On Tue, 12 Nov 2013 06:44:05 -0800, JL wrote:

 I am actually running python on raspberry pi. The trigger event is a
 button-press.
 
 On Monday, November 11, 2013 6:56:03 PM UTC+8, Dave Angel wrote:
 On Mon, 11 Nov 2013 01:41:58 -0800 (PST), JL lightai...@gmail.com
 
 wrote:
 
  - If the event happens again before the 5secs expire, the high
 
 duration will be extended by another 5 secs. This works like a
 
 retriggerable multivibrator for those who are into electronics.
 
 
 
 More precisely a retriggerable monostable multivibrator.
 
 
 
 The question makes little sense unless you're running in an event
 
 driven environment, such as a gui. Name the environment and somebody
 
 can probably help.
 
 
 
 --
 
 DaveA

How critical is the output pulse time?
is it a state that can be polled to regularly  changed if the timeout 
has been exceeded or does it need to switch in the background?

if you need to trigger  switch in the background you will probably need 
to start playing with threads or multiprocessing.

greater detail on what you are trying to achieve project wise may assist 
here
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Tim Chase
On 2013-11-12 17:57, Ferrous Cranus wrote:
  Best practices say to move the value from local time to UTC as
  soon as possible, then store/use the UTC time internally for all
  operations.  Only when it's about to be presented to the user
  should you convert it back to local time if you need to.
 
 or perhaps by confiruing the timezone of the server to use Greece's 
 TimeZone by issuing a linux command?

Regardless of the server's configured TZ, best practice still says to
normalize everything to UTC (ESPECIALLY if Greece uses the
abomination of DST that we suffer here in the US) as soon as
possible and keep it that way for as long as possible.

-tkc


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


Re: datetime question

2013-11-12 Thread William Ray Wing
On Nov 12, 2013, at 10:57 AM, Ferrous Cranus nikos.gr...@gmail.com wrote:

 Στις 12/11/2013 5:54 μμ, ο/η Tim Chase έγραψε:
 On 2013-11-12 17:24, Ferrous Cranus wrote:
 But what of the server was in California and i live in Greece?
 
 How would datetime.now() work then?
 
 Best practices say to move the value from local time to UTC as soon
 as possible, then store/use the UTC time internally for all
 operations.  Only when it's about to be presented to the user should
 you convert it back to local time if you need to.
 
 -tkc
 
 
 
 
 or perhaps by confiruing the timezone of the server to use Greece's TimeZone 
 by issuing a linux command?
 -- 
 

Thus totally screwing all the other users/sites hosted on that server? Thus 
totally screwing up all the housekeeping and maintenance OS tasks that are run 
by chron jobs?

Shakes head in dismay...

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


Re: datetime question

2013-11-12 Thread Alister
On Tue, 12 Nov 2013 09:54:44 -0600, Tim Chase wrote:

 On 2013-11-12 17:24, Ferrous Cranus wrote:
 But what of the server was in California and i live in Greece?
 
 How would datetime.now() work then?
 
 Best practices say to move the value from local time to UTC as soon as
 possible, then store/use the UTC time internally for all operations. 
 Only when it's about to be presented to the user should you convert it
 back to local time if you need to.
 
 -tkc

 it is probably best converted to local time client side (as has already 
been suggested) you may end up with a situation where the server is in 
the USA  your user is in Portugal.
how i you going to identify the users time zone server side(clue you cant 
at least not reliably).

whatever solution you take it is better written as a function rather than 
a single line of code so it can be re-used, you are almost certainly 
going to want this in more than one place


complicated one-liners may look cool to show of your programming skills 
but in the real world they are a maintenance nightmare  are probably 
best avoided.


-- 
The plot was designed in a light vein that somehow became varicose.
-- David Lardner
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: To whoever hacked into my Database

2013-11-12 Thread Antoon Pardon
Op 12-11-13 14:02, Ian Kelly schreef:
 On Tue, Nov 12, 2013 at 2:09 AM, Antoon Pardon
 antoon.par...@rece.vub.ac.be wrote:
 So you are complaining about people being human. Yes that is
 how people tend to react when they continualy are frustrated
 by someone who refuses to show the slightest cooperation.
 So no rejecting such responses, particullarly by the person
 who caused them is not right. It is defelecting the blame from
 the primal cause.
 
 As you say you're a human, not a sheep, so stop pointing at the
 behavior of others to justify your own.

No, because often enough what is justifiable and what is not
depends on the context and what happened before. Morals are
generally not absolute so that a particular action would be
either right or wrong no matter what the circumstances.

 But he started it wasn't an
 excuse in kindergarten, and it still isn't one now.

Then that kindergarten teacher was lousy at her job and would
probably let the bullies maninupulate her in punishing their
victems. That is what you get if you unconditionally tell
people that he started it can't be an excuse.

 Somebody has to
 accept the responsibility to walk away and break the positive feedback
 loop, or it will never end.  And I can't see Nikos being the one to do
 that.

Not my problem. Why do you come to me? I didn't contribute to this
thread for about two days. That is two days of various contributors
that didn't accept their responsibility and whom you left alone.
If it wasn't a problem then that the positive feedback loop was
maintained, then why is it a problem now? I'll start taking you
seriously when I see you tackling the specific behaviour in a
consistent manner instead of you tackling specific contributors.

If you leave a thread alone for four days while various contributors
maintain a positive feedback loop then you are implicitly saying
that such behaviour is not a big problem. So don't come complaining
now.

 That is correct but is expecting too much from people in general.
 Expecting from frustrated people to act rational and constructive
 is just a recipe for your own frustrations.
 
 In my experience, conduct follows from self esteem and self worth, and
 those things follow in turn from the respect and expectations of
 others.  If I expect others to act like animals, then I disrespect
 them, and so why should they behave any differently toward me or in my
 presence?

You are confusing realistic expectations with moralistic expeactations.
In some circumstances it is realistic to expect people to behave like
animals. You may see that as a sign of disrespect but that is because
you assigned it a moral judgement.

 By expecting others to be rational and mature I show my
 respect for them, and so perhaps they will see fit to behave in a way
 to maintain that respect.

No you are not showing respect that way. You are more likely unable
to empathise with the frustrations those people experience and are feeling
smug because you can handle it in such a rational and mature way.

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


Re: datetime question

2013-11-12 Thread Mark Lawrence

On 12/11/2013 16:12, Tim Chase wrote:


Regardless of the server's configured TZ, best practice still says to
normalize everything to UTC (ESPECIALLY if Greece uses the
abomination of DST that we suffer here in the US) as soon as
possible and keep it that way for as long as possible.

-tkc




Why oh why do I have an image of people at Bletchley Park trying to 
switch Colossus from GMT to DOUBLE British Summer Time and back again?


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Implementing a multivibrator function with python

2013-11-12 Thread Antoon Pardon
Op 12-11-13 15:44, JL schreef:
 I am actually running python on raspberry pi. The trigger event is a 
 button-press.

That doesn't help. What does that button-press cause in terms of the OS. Does
it cause a signal? Does it produce a number of bytes that can be read from
some file like object? Something else?

This is not python specific, the answer to those questions is needed no matter
what language you use to implement your function.

-- 
Antoon Pardon



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


Re: Implementing a multivibrator function with python

2013-11-12 Thread Joel Goldstick
On Tue, Nov 12, 2013 at 11:37 AM, Antoon Pardon
antoon.par...@rece.vub.ac.be wrote:
 Op 12-11-13 15:44, JL schreef:
 I am actually running python on raspberry pi. The trigger event is a 
 button-press.

 That doesn't help. What does that button-press cause in terms of the OS. Does
 it cause a signal? Does it produce a number of bytes that can be read from
 some file like object? Something else?

 This is not python specific, the answer to those questions is needed no matter
 what language you use to implement your function.

This interests me because I started out in Electrical engineering
school in college.  I'm intrigued by raspberry pi.  I bet you would
find specific answers reading about how the hardware works.  Does
Raspberry pi come with push buttons that are connected to some io
ports or a usb port or a keyboard or?

If there is no physical switch, one of the gui frameworks for python
certainly will have hooks to invoke code when a (virtual) button is
pressed.

Maybe find a Raspberry pi newsgroup?



 --
 Antoon Pardon



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



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


Re: PyMyth: Global variables are evil... WRONG!

2013-11-12 Thread Rick Johnson
On Tuesday, November 12, 2013 9:33:50 AM UTC-6, jongiddy wrote:
 I'm not sure where you get the feeling you're accessing an
 interface.

Because the constant PI should never change. Sure we can
argue about granularity of PI, but that argument has no
weight on the fact that PI should be a constant.

By placing PI in the module math, we are creating a pseudo
interface. We (the creators) are assuming that PI will be a
constant and never change, and the caller is assuming that
pi will remain static,  but not only can it be mutated, it
can be mutated globally.

math.pi is neither a constant nor a local module attribute,
math.pi is really a global variable. This is true not only
for math.pi, but ALL attributes of ALL python modules.

 If I typed this, I would feel like I was trying
 to change a fundamental constant. You have just
 demonstrated that going into other modules and changing
 their attributes (whether they are variables, functions or
 classes) is generally a BAD idea, and I don't think I've
 ever seen anyone recommend doing this, except possibly as
 a workaround or for debugging purposes. On the other hand,
 you initially suggested that modifying globals contained
 within namespaces (i.e. modules) is a good way to
 communicate between modules.

You missed my point: only IF python modules were TRUE
interfaces. It's not a good idea under python's current
implementation of modules. My thread is intended to
underscore this very design flaw.

 This inconsistency

There is no inconsistency in my logic, quite the contrary.

I think you're having difficulty following along because
you've been brainwashed by Python for too long. You've
falsely believed that Python does not have globals, but
it does! You just have to mutate then via a pseudo
interface.

 is why I was asking for a good example (i.e.
 a realistic example where the use of global variables
 provides the best solution).

I gave a good example in my very first post:

RR: Globals are justified when they are used to
[share] information between scopes that otherwise
were meant to be mutually exclusive. One good
example would be package sub-modules.

 Just because a tool allows you to do something does not
 make it a good idea. Try this paraphrase of your last
 post: Ladder designers act like standing on the top rung
 is SO evil, but then they give us ladders with a top rung,
 Are they just trying to fool themselves, or fool us?

EXACTLY. And whilst your comparison is both intelligent and
funny, you're just re-iterating my point!

We have all been brainwashed by authorities. First they
give us rules, then they give us the power to break
those rules. If standing on the top rung is SO
dangerous, then don't manufacture your ladders with top
rungs. Else, shut up about it!

  THOU SHALT NOT KILL

Well i can't live WITH the B!@$%!!!

  THOU SHALT NOT COMMIT ADULTERY

Then why create me with a unquenchable desire for sex?

  THOU SHALT NOT TAKE THE LORDS NAME IN VAIN

GOD DAMMIT! Stop making all these opposing rules.

So the designers detest globals huh? But python module
attributes are really global because they can be accessed
and mutated ANYWHERE!. This enigma leads to two logical
design philosophies: (anything else is folly)

   1. Accept that globals are useful, and make them
  available through a real global syntax, not
  some attribute of a module that appears to be
  local, but in reality is global. Then prevent
  external mutation of module attributes directly,
  and instead, require that mutation must follow a
  contract defined by internal module setter
  functions.

   2. Remain convinced that global mutation is evil
  and prevent mutation of all python module
  attributes. You can import modules, but you can't
  mutate their contents.

THIS IS HOW YOU DESIGN FOR CONSISTENCY, NOT HYPOCRISY!

@LanguageDesigners: But whatever you do, don't hide globals
behind pseudo interfaces, because then you have created
something worse than a global; you've created a global in
sheep's clothing. And you're a hypocrite.


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


Re: Show off your Python chops and compete with others

2013-11-12 Thread Nathaniel Sokoll-Ward
Hi Omar,

Thanks for the suggestions!

Your point about question difficulty is well taken. We previously organized
questions into sections based on difficulty or topic, but have been
experimenting with doing away with sections entirely. We are developing a
way to intelligently deliver questions to a user based on their perceived
skill level.

You're right that our checks can be defeated with sneakiness, but in the
end we believe that it makes more sense to implement incentives to
encourage people to post high quality answers, than to build full-proof
validation tools.

Thanks again!


On Thu, Nov 7, 2013 at 11:09 PM, Omar Abou Mrad omar.aboum...@gmail.comwrote:


 On Thu, Nov 7, 2013 at 2:00 AM, Nathaniel Sokoll-Ward 
 nathanielsokollw...@gmail.com wrote:

 Thought this group would appreciate this:
 www.metabright.com/challenges/python

 MetaBright makes skill assessments to measure how talented people are at
 different skills. And recruiters use MetaBright to find outrageously
 skilled job candidates.

 Python is a new area of expertise for us. We make Challenges for a
 bunch of languages and we're excited to finally have Python released. Give
 it a shot -- I'd love to hear what you think.
 --
 https://mail.python.org/mailman/listinfo/python-list


 Nathaniel,

 You may want to classify the questions under some weight. You can't really
 have a level 6 question about semi colon.

 Also, when the boss questions are being computed, you should run more than
 the 'example' given as a test, otherwise users can just cheat. For example,
 I think one of the 'Boss' question was return the first 3 digits of PI as a
 list, all i did was:

 return [3,1,4]

 Hope this helps.


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


Re: PyMyth: Global variables are evil... WRONG!

2013-11-12 Thread Tim Chase
On 2013-11-12 09:00, Rick Johnson wrote:
 Because the constant PI should never change. Sure we can
 argue about granularity of PI, but that argument has no
 weight on the fact that PI should be a constant.
 
 By placing PI in the module math, we are creating a pseudo
 interface. We (the creators) are assuming that PI will be a
 constant and never change, and the caller is assuming that
 pi will remain static,  but not only can it be mutated, it
 can be mutated globally.

But the module-scoping of globals is perfectly valid:

  print(math.PI)
 3.1415926535897932
  print(Magnum.PI)
 Tom Selleck

As an example from the stdlib of setting globals via a protocol,
locale.setlocale() does exactly this.  So I'm not sure why you have
your knickers in a knot.  Module-level items can be accessed
globally (though often a bad idea, or at least you have to beware of
side-effects where other things might break), and if you don't like
the modules are not objects, someone in this thread already showed
you that you can insert objects/classes into the sys.modules and get
full getter/setter functionality with minimal trouble.

Finally, we're all (mostly) consenting adults here.  If I want to be
an idiot and

  math.PI = 3.14

and suddenly stuff breaks, I get to keep all the pieces my breakage
caused.

-tkc



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


Re: PyMyth: Global variables are evil... WRONG!

2013-11-12 Thread Rick Johnson
On Tuesday, November 12, 2013 11:00:37 AM UTC-6, Rick Johnson wrote:
[snip]
 We have all been brainwashed by authorities. First they
 give us rules, then they give us the power to break
 those rules. 

The devil himself said it best:

  http://www.youtube.com/watch?v=RGR4SFOimlk

Hmm. How do we humans cope with all these opposing rules? If
we created an AI with all the ridiculous, convoluted and
opposing rules that we humans live with on a daily basis, it
would blow chunks.

How do our minds possibly cope with such illogical rules
without blowing chunks?

We cope by re-inventing reality.  We cope by convincing
ourselves that truths are not true and lies are true.

We cope by designing languages that obfuscate globals behind
pseudo interfaces so we can get farm fuzzy feelings in our
tummy, then we can secretly break the rule when non-one is
looking.

By doing this we convince ourselves that we are pure.

HUMANS: What a pathetic bunch of slaves!

 http://www.youtube.com/watch?v=PFdmAgA_Gfo


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


Re: UTF-32 decoder optimization in Python 3.4

2013-11-12 Thread wxjmfauth
Le mardi 12 novembre 2013 03:11:48 UTC+1, Terry Reedy a écrit :
 On 11/11/2013 4:41 PM, Mark Lawrence wrote:
 
   From http://docs.python.org/dev/whatsnew/3.4.html#optimizations The
 
  UTF-32 decoder is now 3x to 4x faster..  Does anybody have any
 
  references to this work?  All I can find is the 3.3 what's new which
 
  refers to PEP 393 (Flexible String Representation) optimizations as a
 
  result of work done by Serhiy Storchaka on issues 14624, 14738 and 15026.
 
 
 
 The second line at the top has For full details, see the changelog. 
 
 where changelog links to
 
 http://docs.python.org/3.4/whatsnew/changelog.html
 
 Searching that for 'UTF-34' goes to this line
 
 Issue #14625: Rewrite the UTF-32 decoder. It is now 3x to 4x faster. 
 
 Patch written by Serhiy Storchaka. where 'Issue #14625' links to
 
 http://bugs.python.org/issue14625
 
 with full discussion. (I know that you, Mark, could have found that, but 
 
 not everyone reading could.)
 
 
 
 -- 
 
 Terry Jan Reedy

I'm not so sure, I understood the last sentence correctly.
If you are thinking about me, yes I'm aware of it.

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


Re: datetime question

2013-11-12 Thread MRAB

On 12/11/2013 16:12, Tim Chase wrote:

On 2013-11-12 17:57, Ferrous Cranus wrote:

 Best practices say to move the value from local time to UTC as
 soon as possible, then store/use the UTC time internally for all
 operations.  Only when it's about to be presented to the user
 should you convert it back to local time if you need to.

or perhaps by confiruing the timezone of the server to use Greece's
TimeZone by issuing a linux command?


Regardless of the server's configured TZ, best practice still says to
normalize everything to UTC (ESPECIALLY if Greece uses the
abomination of DST that we suffer here in the US) as soon as
possible and keep it that way for as long as possible.


FTR, the countries in the EU all change at the same (UTC) time.
--
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Joel Goldstick
On Tue, Nov 12, 2013 at 2:09 PM, MRAB pyt...@mrabarnett.plus.com wrote:
 On 12/11/2013 16:12, Tim Chase wrote:

 On 2013-11-12 17:57, Ferrous Cranus wrote:

  Best practices say to move the value from local time to UTC as
  soon as possible, then store/use the UTC time internally for all
  operations.  Only when it's about to be presented to the user
  should you convert it back to local time if you need to.

 or perhaps by confiruing the timezone of the server to use Greece's
 TimeZone by issuing a linux command?


 Regardless of the server's configured TZ, best practice still says to
 normalize everything to UTC (ESPECIALLY if Greece uses the
 abomination of DST that we suffer here in the US) as soon as
 possible and keep it that way for as long as possible.

 FTR, the countries in the EU all change at the same (UTC) time.
 --
 https://mail.python.org/mailman/listinfo/python-list

In the US, the state of Indiana is really weird.  Three separate time
zone areas, that don't all flip in the same way.  See this for TZ
hell:  http://en.wikipedia.org/wiki/Indiana_time_zones

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


using print() with multiprocessing and pythonw

2013-11-12 Thread Isaac Gerg
I launch my program with pythonw and begin it with the code below so that all 
my print()'s go to the log file specified. 

if sys.executable.find('pythonw') =0:
# Redirect all console output to file.
sys.stdout = open(pythonw - stdout stderr.log,'w')
sys.stderr = sys.stdout

During the course of my program, I call multiprocessing.Process() and launch a 
function several times.  That function has print()'s inside (which are from 
warnings being printed by python).  This printing causes the multiprocess to 
crash.  How can I fix my code so that the print()'s are supressed. I would hate 
to do a warnings.filterwarnings('ignore') because when I unit test those 
functions, the warnings dont appear.

Thanks in advance,
Isaac
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Denis McMahon
On Tue, 12 Nov 2013 12:47:58 +, Andy Lawton wrote:

 (I think Europe/Kiev is Greece but I don't know)

I suspect Nick is really in a coding sweatshop in Asia/Mumbai

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


Re: datetime question

2013-11-12 Thread Denis McMahon
On Tue, 12 Nov 2013 17:57:55 +0200, Ferrous Cranus wrote:

 or perhaps by confiruing the timezone of the server to use Greece's
 TimeZone by issuing a linux command?

If you have that degreee of control over the server, yes, but UTC is 
always safer, because if you need to move your server to a different site 
(eg disaster recovery) UTC is still UTC.

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


ANN: Leo 4.11 final released: Python scripting IDE

2013-11-12 Thread edreamleo
Leo 4.11 final is now available at: 
http://sourceforge.net/projects/leo/files/Leo/ Leo 4.11 contains over a year's 
work on Leo.

Leo is a PIM, an IDE and an outliner for programmers, authors and web
designers. Leo's unique features organize data in a revolutionary way.
Python scripts can easily access all parts of Leo outlines.
See http://leoeditor.com/tutorial.html

The highlights of Leo 4.11:
---

- Leo's tutorials have been rewritten and simplified.
- Greatly improved abbreviations, including templates.
- Clones are now valid anywhere in @file nodes.
- Leo now warns if a .leo file is open elsewhere.
- Leo's IPython bridge now works with IPython 1.x.
- Added support for @testsetup and @testclass.
- Added support for sessions.
- Added colorizing themes.
- A colored border highlights the pane with focus.
- Added support for the clojure, markdown and TypeScript languages.
- Added importers for .ipynb, .otl and vimoutliner files.
- Many new and improved commands, plugins and scripts.
- Dozens of bug fixes and code-level improvements.

Links:
--
Leo:   http://leoeditor.com
Docs:  http://leoeditor.com/leo_toc.html
Tutorials: http://leoeditor.com/tutorial.html
Forum: http://groups.google.com/group/leo-editor
Download:  http://sourceforge.net/projects/leo/files/
Bzr:   http://code.launchpad.net/leo-editor/
Quotes:http://leoeditor.com/testimonials.html

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


Re: using print() with multiprocessing and pythonw

2013-11-12 Thread William Ray Wing
On Nov 12, 2013, at 2:12 PM, Isaac Gerg isaac.g...@gergltd.com wrote:

 I launch my program with pythonw and begin it with the code below so that all 
 my print()'s go to the log file specified. 
 
 if sys.executable.find('pythonw') =0:
# Redirect all console output to file.
sys.stdout = open(pythonw - stdout stderr.log,'w')
sys.stderr = sys.stdout
 
 During the course of my program, I call multiprocessing.Process() and launch 
 a function several times.  That function has print()'s inside (which are from 
 warnings being printed by python).  This printing causes the multiprocess to 
 crash.  How can I fix my code so that the print()'s are supressed. I would 
 hate to do a warnings.filterwarnings('ignore') because when I unit test those 
 functions, the warnings dont appear.
 
 Thanks in advance,
 Isaac
 -- 
 https://mail.python.org/mailman/listinfo/python-list

This may be inelegant, but it solved a similar problem for me.  Replace the 
print statements with logging.info statements and have each invocation of the 
function dump to a unique log file (with a name based on the function's input). 
 At least in my case, multiprocessing seemed to get its feet tangled (crash) 
when different subprocesses tried to print to the same output file at the same 
time.

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


Re: using print() with multiprocessing and pythonw

2013-11-12 Thread Isaac Gerg
Thanks for the reply Bill.  The problem is the text i am getting is from a 
python warning message, not one of my own print() function calls.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: To whoever hacked into my Database

2013-11-12 Thread Ian Kelly
On Tue, Nov 12, 2013 at 9:27 AM, Antoon Pardon
antoon.par...@rece.vub.ac.be wrote:
 Op 12-11-13 14:02, Ian Kelly schreef:
 On Tue, Nov 12, 2013 at 2:09 AM, Antoon Pardon
 antoon.par...@rece.vub.ac.be wrote:
 So you are complaining about people being human. Yes that is
 how people tend to react when they continualy are frustrated
 by someone who refuses to show the slightest cooperation.
 So no rejecting such responses, particullarly by the person
 who caused them is not right. It is defelecting the blame from
 the primal cause.

 As you say you're a human, not a sheep, so stop pointing at the
 behavior of others to justify your own.

 No, because often enough what is justifiable and what is not
 depends on the context and what happened before. Morals are
 generally not absolute so that a particular action would be
 either right or wrong no matter what the circumstances.

I never claimed that they are.  That doesn't mean that when somebody
misbehaves, you can do whatever you want in retaliation without regard
for others who might be involved.

 But he started it wasn't an
 excuse in kindergarten, and it still isn't one now.

 Then that kindergarten teacher was lousy at her job and would
 probably let the bullies maninupulate her in punishing their
 victems. That is what you get if you unconditionally tell
 people that he started it can't be an excuse.

Yes, when one kid is yelling at another kid because the second kid
pulled the first kid's hair, the teacher should just ignore the
yelling because, after all, he started it.  I'm sure that won't
cause any disruption in the classroom at all, and having one kid
yelling probably isn't going to set any of the others off, is it?

As for letting the bullies (which I'll take as a metaphor for
trolls, since I've not once seen Nikos act like a bully) get away with
things, none of these threads have been about pursuing any sort of
justice, so don't try to frame the discussion as if they are.

 Somebody has to
 accept the responsibility to walk away and break the positive feedback
 loop, or it will never end.  And I can't see Nikos being the one to do
 that.

 Not my problem. Why do you come to me? I didn't contribute to this
 thread for about two days. That is two days of various contributors
 that didn't accept their responsibility and whom you left alone.
 If it wasn't a problem then that the positive feedback loop was
 maintained, then why is it a problem now? I'll start taking you
 seriously when I see you tackling the specific behaviour in a
 consistent manner instead of you tackling specific contributors.

My apologies then for implying that you have been actively feeding the
troll; I have not been paying attention to who is or isn't doing that.
 I replied to you because you've been very vocal on the topic, and
because you wrote things that I wanted to respond to, not to single
you out as the problem.  I'm not going to individually address every
single person who I think is contributing to the problem, because
that's not my job and I don't have time for it.  If you think that's
not being fair, then that's tough, but this mailing list is not a
kindergarten.  We're all adults here, and I expect that others who are
feeding the troll will have the maturity and self-awareness to
recognize that what I wrote applies to them without me having to
repeat myself a dozen times.

 If you leave a thread alone for four days while various contributors
 maintain a positive feedback loop then you are implicitly saying
 that such behaviour is not a big problem. So don't come complaining
 now.

I've spoken up on this issue before.  I'm not going to repetitively
respond to every single post or even every single thread that I think
is problematic.  If I did that, then I would be part of the problem.
As I said above, I chose to speak up now because you wrote things that
I specifically wanted to respond to.  For the most part however I
prefer silence in the knowledge that making noise just invites more
noise.  For that reason you can expect that I will drop out of this
thread again shortly, likely after this post.

 That is correct but is expecting too much from people in general.
 Expecting from frustrated people to act rational and constructive
 is just a recipe for your own frustrations.

 In my experience, conduct follows from self esteem and self worth, and
 those things follow in turn from the respect and expectations of
 others.  If I expect others to act like animals, then I disrespect
 them, and so why should they behave any differently toward me or in my
 presence?

 You are confusing realistic expectations with moralistic expeactations.
 In some circumstances it is realistic to expect people to behave like
 animals. You may see that as a sign of disrespect but that is because
 you assigned it a moral judgement.

 By expecting others to be rational and mature I show my
 respect for them, and so perhaps they will see fit to behave in a way
 to maintain that respect.

 No you 

Chinese Zodiac - python project

2013-11-12 Thread edmundicon
Greetings everyone! This is my first post on this forum :)

TL;DR: I want to convert the gregorian years into Chinese years, and deal with 
the fact that the Chinese new years are different each gregorian year. If I 
manage to do that, I'll know which year the user is born in Chinese years and 
can then give him a personal description based upon that year!

I started to learn Python programming language 2 months ago (noob), but I like 
it and I feel like if I keep learning I might become a great programmer one day!

I recently started a small Python project in which my mission is to give a 
personal description to a user based upon the year he / she is born in the 
Chinese Zodiac and I have run into some trouble. For instance, if someone is 
born on the 15'th January 1990, he is actually born 1989 because the Chinese 
new year occurred on the 27:th January that year.

I have a text file which shows when the Chinese new years in gregorian years 
(normal years), starting from 1900-01-31 to 2007-02-18. It goes like this:
1900-1-31
1901-2-19
1902-2-08
1903-1-29
1904-2-16
1905-2-04
1906-1-25 ...(and so on)
2007-02-18 ( I can't see the logic behind this really)

The Chinese calendar is divided into cycles of 60 years each, and each year has 
a combination of an animal and an element. There are 12 animals and 5 elements, 
the animals changes each year, and the elements every other year. The current 
cycle was initiated in the year of 1984 which was the year of the Wood Rat. The 
personal descriptions for each combination has conveniently also been provided 
in text files. 

The animals are in this order:

Rat
Ox
Tiger
Rabbit
Dragon
Snake
Horse
Sheep
Monkey
Rooster
Dog
Boar

And the elements are:

Wood
Fire
Earth
Metal
Water

I have already created a modulus method which takes the input year (the 
gregorian year you were born) and gives you an element and an animal, for 
example if you type 1990 you are given Metal Horse. The problem I now have is 
to convert the gregorian years into Chinese years, and deal with the fact that 
the Chinese new years are different each gregorian year. If I manage to do 
that, I'll know which year the user is born in Chinese years and can then give 
him a personal description based upon that year!

Any advice will be greatly appreciated! Have a nice day :)

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


Some python newb help please?

2013-11-12 Thread lrwarren94
So I'm trying to write a program for a problem in class, and something strange 
is happening that I can't figure out why is happening. I was wondering if you 
guys could help me fix it?

http://pastebin.com/6QZTvx6Z

Basically, 1 and 2 work just fine as inputs, but whenever I input 3 or 4, idle 
just doesn't do anything. Does anyone know why that is? any suggestions on how 
to fix? Any help is much appreciated :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Some python newb help please?

2013-11-12 Thread Mark Lawrence

On 12/11/2013 22:14, lrwarre...@gmail.com wrote:

So I'm trying to write a program for a problem in class, and something strange 
is happening that I can't figure out why is happening. I was wondering if you 
guys could help me fix it?

http://pastebin.com/6QZTvx6Z

Basically, 1 and 2 work just fine as inputs, but whenever I input 3 or 4, idle 
just doesn't do anything. Does anyone know why that is? any suggestions on how 
to fix? Any help is much appreciated :)



Please put your code inline so we can see it, if it's too long see this 
http://sscce.org/ for advice.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Some python newb help please?

2013-11-12 Thread lrwarren94
On Tuesday, November 12, 2013 4:21:58 PM UTC-6, Mark Lawrence wrote:
 On 12/11/2013 22:14, lr@gmail.com wrote:
 
  So I'm trying to write a program for a problem in class, and something 
  strange is happening that I can't figure out why is happening. I was 
  wondering if you guys could help me fix it?
 
 
 
  http://pastebin.com/6QZTvx6Z
 
 
 
  Basically, 1 and 2 work just fine as inputs, but whenever I input 3 or 4, 
  idle just doesn't do anything. Does anyone know why that is? any 
  suggestions on how to fix? Any help is much appreciated :)
 
 
 
 
 
 Please put your code inline so we can see it, if it's too long see this 
 
 http://sscce.org/ for advice.
 
 
 
 -- 
 
 Python is the second best programming language in the world.
 
 But the best has yet to be invented.  Christian Tismer
 
 
 
 Mark Lawrence

I'm not quite sure what you mean by that. it was on that pastebin link. I'll 
post it again here though. it's no longer than half a page. 

x = 0
y = 0
quitCommand = 0

print Welcome to the World of Textcraft!
print --
print 

while quitCommand != int(5):
print You are currently at ( + str(x) + ,  + str(y) + )
print Enter a command (1 = North, 2 = East, 3 = South, 4 = West, 5 = 
Exit):
if int(raw_input()) == 1:
print Moving north
y = y + 1
elif int(raw_input()) == 2:
print Moving east
x = x + 1
elif int(raw_input()) == 3:
print Moving south
y = y - 1
elif int(raw_input()) == 4:
print Moving west
x = x - 1
elif int(raw_input()) == 5:
print Dost thou leave so soon? Fare thee well!
quitCommand = 5
else:
print I find your lack of reading comprehension skills disturbing.


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


Re: datetime question

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 6:14 AM, Joel Goldstick
joel.goldst...@gmail.com wrote:
 In the US, the state of Indiana is really weird.  Three separate time
 zone areas, that don't all flip in the same way.  See this for TZ
 hell:  http://en.wikipedia.org/wiki/Indiana_time_zones

Timezones are one of the most interesting [1] things in the world.
Ireland doesn't move clocks forward for summer time, they move them
backward for winter time... I swear, when I first heard that, I
thought it was just one of those Irish jokes with no basis, but it is
true...

https://en.wikipedia.org/wiki/Time_in_the_Republic_of_Ireland

Plus, they switch clocks at 2am all the time, not at 2am forward and
3am backward.

ChrisA

[1] Define interesting.
http://www.imdb.com/title/tt0379786/quotes?item=qt0433039
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyMyth: Global variables are evil... WRONG!

2013-11-12 Thread jongiddy
On Tuesday, November 12, 2013 5:00:37 PM UTC, Rick Johnson wrote: 
 
 
1. Accept that globals are useful, and make them
 
   available through a real global syntax, not
 
   some attribute of a module that appears to be
 
   local, but in reality is global. Then prevent
 
   external mutation of module attributes directly,
 
   and instead, require that mutation must follow a
 
   contract defined by internal module setter
 
   functions.
 
 
 
2. Remain convinced that global mutation is evil
 
   and prevent mutation of all python module
 
   attributes. You can import modules, but you can't
 
   mutate their contents.

From your first post, I take it you're not keen on option #2.

For #1, module globals are exactly the hierarchically namespaced globals that 
you desire in your first post, except they are variables, not get/set handlers 
(which is what I take you to mean by an interface).

Why not create a PEP to provide handlers for module attributes? You could base 
it on PEP 213, which describes the same feature for classes.

As a bonus, this would trivially support option #2 (e.g. non-mutable math.pi) 
by raising an exception for the set operator.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: To whoever hacked into my Database

2013-11-12 Thread Ethan Furman

On 11/12/2013 01:26 PM, Ian Kelly wrote:


As for letting the bullies (which I'll take as a metaphor for
trolls, since I've not once seen Nikos act like a bully)


Every time he uses foul language against somebody he's acting like a bully.

Every time he reposts questions and ignores answers he's acting like a bully.

Every time he declares that what he wants is the most important and so he is going to ignore our culture and the topic 
of this forum/ml/ng he is acting like a bully.


If you haven't seen those posts, I have.  Now you know.

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


Re: Some python newb help please?

2013-11-12 Thread John Strick
Welcome to the world of Python programming! I'm glad you're learning this great 
language. 

As to your bug, think about this: in each if or elif statement, you're reading 
the user input again, so if user input is NOT equal to 1 in the first place, it 
reads input again. Try to step through your code mentally, or even on paper, 
and track *exactly* what's happening. You could also add some print statements 
to see where you are. Good luck with your coding.

Consider reading user input only once, and then checking it against the values 
1,2,3,4, and 5.

As an aside, int(5) is from the department of redundancy department. ;-)

--John Strickler

On Tuesday, November 12, 2013 5:14:42 PM UTC-5, lrwar...@gmail.com wrote:
 So I'm trying to write a program for a problem in class, and something 
 strange is happening that I can't figure out why is happening. I was 
 wondering if you guys could help me fix it?
 
 
 
 http://pastebin.com/6QZTvx6Z
 
 
 
 Basically, 1 and 2 work just fine as inputs, but whenever I input 3 or 4, 
 idle just doesn't do anything. Does anyone know why that is? any suggestions 
 on how to fix? Any help is much appreciated :)

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


Re: Some python newb help please?

2013-11-12 Thread Mark Lawrence
First thing would you please read and action this 
https://wiki.python.org/moin/GoogleGroupsPython so we don't have to read 
double spaced google crap, thanks.


On 12/11/2013 22:27, lrwarre...@gmail.com wrote:

On Tuesday, November 12, 2013 4:21:58 PM UTC-6, Mark Lawrence wrote:

On 12/11/2013 22:14, lr@gmail.com wrote:


So I'm trying to write a program for a problem in class, and something strange 
is happening that I can't figure out why is happening. I was wondering if you 
guys could help me fix it?







http://pastebin.com/6QZTvx6Z







Basically, 1 and 2 work just fine as inputs, but whenever I input 3 or 4, idle 
just doesn't do anything. Does anyone know why that is? any suggestions on how 
to fix? Any help is much appreciated :)








Please put your code inline so we can see it, if it's too long see this

http://sscce.org/ for advice.



--

Python is the second best programming language in the world.

But the best has yet to be invented.  Christian Tismer



Mark Lawrence


I'm not quite sure what you mean by that. it was on that pastebin link. I'll 
post it again here though. it's no longer than half a page.

x = 0
y = 0
quitCommand = 0

print Welcome to the World of Textcraft!
print --
print 


You don't need the double quotes in the line above, the print statement 
on its own will output a newline.




while quitCommand != int(5):
 print You are currently at ( + str(x) + ,  + str(y) + )
 print Enter a command (1 = North, 2 = East, 3 = South, 4 = West, 5 = 
Exit):
 if int(raw_input()) == 1:
 print Moving north
 y = y + 1
 elif int(raw_input()) == 2:
 print Moving east
 x = x + 1
 elif int(raw_input()) == 3:
 print Moving south
 y = y - 1
 elif int(raw_input()) == 4:
 print Moving west
 x = x - 1
 elif int(raw_input()) == 5:
 print Dost thou leave so soon? Fare thee well!
 quitCommand = 5
 else:
 print I find your lack of reading comprehension skills 
disturbing.




You're asking for input in every comparison.  Change this to request the 
input once, store it and then compare it.  If you rename quitCommand to 
command, you'd have


command = int(raw_input())
if command == 1:
etc.

Enjoy :)

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Chinese Zodiac - python project

2013-11-12 Thread Denis McMahon
On Tue, 12 Nov 2013 14:04:08 -0800, edmundicon wrote:

 Greetings everyone! This is my first post on this forum :)
 
 TL;DR: I want to convert the gregorian years into Chinese years, and
 deal with the fact that the Chinese new years are different each
 gregorian year. If I manage to do that, I'll know which year the user is
 born in Chinese years and can then give him a personal description based
 upon that year!
 
 I started to learn Python programming language 2 months ago (noob), but
 I like it and I feel like if I keep learning I might become a great
 programmer one day!
 
 I recently started a small Python project in which my mission is to give
 a personal description to a user based upon the year he / she is born in
 the Chinese Zodiac and I have run into some trouble. For instance, if
 someone is born on the 15'th January 1990, he is actually born 1989
 because the Chinese new year occurred on the 27:th January that year.
 
 I have a text file which shows when the Chinese new years in gregorian
 years (normal years), starting from 1900-01-31 to 2007-02-18. It goes
 like this:
 1900-1-31 1901-2-19 1902-2-08 1903-1-29 1904-2-16 1905-2-04 1906-1-25
 ...(and so on)
 2007-02-18 ( I can't see the logic behind this really)
 
 The Chinese calendar is divided into cycles of 60 years each, and each
 year has a combination of an animal and an element. There are 12 animals
 and 5 elements, the animals changes each year, and the elements every
 other year. The current cycle was initiated in the year of 1984 which
 was the year of the Wood Rat. The personal descriptions for each
 combination has conveniently also been provided in text files.
 
 The animals are in this order:
 
 Rat Ox Tiger Rabbit Dragon Snake Horse Sheep Monkey Rooster Dog Boar
 
 And the elements are:
 
 Wood Fire Earth Metal Water
 
 I have already created a modulus method which takes the input year (the
 gregorian year you were born) and gives you an element and an animal,
 for example if you type 1990 you are given Metal Horse. The problem I
 now have is to convert the gregorian years into Chinese years, and deal
 with the fact that the Chinese new years are different each gregorian
 year. If I manage to do that, I'll know which year the user is born in
 Chinese years and can then give him a personal description based upon
 that year!
 
 Any advice will be greatly appreciated! Have a nice day :)

Here is one suggestion

Write a function to convert a gregorian date into the number of days 
since 1st January 1900 (we'll call 1st january 1900 your epoch). You will 
need to take leap years into account.

Convert the users date of birth using this function.

Convert your chinese new year dates using this function.

You now have the simple task of comparing the users date of birth as 
daynumber_since_epoch with the start date of each chinese year as 
daynumber_since_epoch.

You may wish to create a list of tuples where each tuple has start_day, 
end_day, year_name:

years = [(0,30,stone pig),(31,414,stone weasel) ... ]

You should be able to automate creating this list.

You could then search through the list of tuples with a function such as:

yearname( birthdate ):
foreach thing in years
if birthdate is in the range specified by the thing
return the yearname from the thing
return constipated program

(this is obviously not written as python code, you have to do that bit 
yourself)

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


Re: Some python newb help please?

2013-11-12 Thread Tim Chase
On 2013-11-12 14:27, lrwarre...@gmail.com wrote:
 if int(raw_input()) == 1:
 print Moving north
 y = y + 1
 elif int(raw_input()) == 2:
 print Moving east
 x = x + 1
 elif int(raw_input()) == 3:
 print Moving south
 y = y - 1
 elif int(raw_input()) == 4:
 print Moving west
 x = x - 1
 elif int(raw_input()) == 5:
 print Dost thou leave so soon? Fare thee well!
 quitCommand = 5
 else:
 print I find your lack of reading comprehension skills
 disturbing.

Note that you're asking for input with each comparison.  Best to get
the input once and store it in a variable before the if statement
and then do the comparisons against the same value.

-tkc

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


Re: Some python newb help please?

2013-11-12 Thread MRAB
On 12/11/2013 22:27, lrwarre...@gmail.com wrote: On Tuesday, November 
12, 2013 4:21:58 PM UTC-6, Mark Lawrence wrote:

 On 12/11/2013 22:14, lr@gmail.com wrote:

  So I'm trying to write a program for a problem in class, and 
something strange is happening that I can't figure out why is happening. 
I was wondering if you guys could help me fix it?

 
[snip]

 x = 0
 y = 0
 quitCommand = 0

 print Welcome to the World of Textcraft!
 print --
 print 

You can simplify that to:

print


 while quitCommand != int(5):

5 is already an int, so int(5) == 5.

  print You are currently at ( + str(x) + ,  + str(y) + )
  print Enter a command (1 = North, 2 = East, 3 = South, 4 = 
West, 5 = Exit):

  if int(raw_input()) == 1:

You're asking the user to enter something and then checking whether its 
int value is 1.


  print Moving north
  y = y + 1
  elif int(raw_input()) == 2:

Now you're asking the user to enter something _again_ and then checking 
whether its int value is 2.


In other words, in order for it to print Moving east the following 
steps must occur:


1. Ask the user to enter something.

2. Check whether it's 1. It isn't. (Previous condition)

3. Ask the user to enter something.

4. Check whether it's 2. (This condition)

  print Moving east
  x = x + 1
  elif int(raw_input()) == 3:

Similar remarks to above, but longer.

  print Moving south
  y = y - 1
  elif int(raw_input()) == 4:

Similar remarks to above, but longer again.

  print Moving west
  x = x - 1
  elif int(raw_input()) == 5:

Similar remarks to above, but longer again.

  print Dost thou leave so soon? Fare thee well!
  quitCommand = 5
  else:
  print I find your lack of reading comprehension skills 
disturbing.



The fix is simple. Ask once:

 answer = int(raw_input())
 if answer == 1:
 ...
 elif answer == 2:
 ...
 ...
--
https://mail.python.org/mailman/listinfo/python-list


Re: Some python newb help please?

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 9:27 AM,  lrwarre...@gmail.com wrote:
 I'm not quite sure what you mean by that. it was on that pastebin link. I'll 
 post it again here though. it's no longer than half a page.

Inline means what you did in this post. Out-of-line means providing us
with a link to where the code is.

This forum isn't just a Google Groups web-based discussion group; it's
primarily a newsgroup (comp.lang.python) and an email address
(python-list@python.org). Both of those can be read by people who
don't have internet access, so putting your code in an http link might
prevent them from reading it. Also, the group/list gets archived all
over the place, and there's no guarantee that pastebin will still be
around a hundred years from now. It's an unnecessary dependency, which
inline code doesn't have. That's why posting right here is the safe
option :)

Two general comments. Firstly, you're using Python 2 here. Is there a
reason for that? If you possibly can, switch to Python 3. All sorts of
things have been improved, and the gap is only going to widen - there
won't be a Python 2.8, and subsequent 2.7.x releases are bugfixes and
security patches only. All the new shinies are in 3.x. And secondly,
please PLEASE avoid Google Groups; your quoted text is ugly and
annoying, and your own text isn't wrapped. Check this out, and
preferably, find an alternative means of posting:

https://wiki.python.org/moin/GoogleGroupsPython

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


Re: Some python newb help please?

2013-11-12 Thread lrwarren94
On Tuesday, November 12, 2013 4:56:35 PM UTC-6, MRAB wrote:
 On 12/11/2013 22:27, l...@gmail.com wrote: On Tuesday, November 
 
 12, 2013 4:21:58 PM UTC-6, Mark Lawrence wrote:
 
   On 12/11/2013 22:14, lr@gmail.com wrote:
 
  
 
So I'm trying to write a program for a problem in class, and 
 
 something strange is happening that I can't figure out why is happening. 
 
 I was wondering if you guys could help me fix it?
 
   
 
 [snip]
 
  
 
   x = 0
 
   y = 0
 
   quitCommand = 0
 
  
 
   print Welcome to the World of Textcraft!
 
   print --
 
   print 
 
 
 
 You can simplify that to:
 
 
 
  print
 
 
 
  
 
   while quitCommand != int(5):
 
 
 
 5 is already an int, so int(5) == 5.
 
 
 
print You are currently at ( + str(x) + ,  + str(y) + )
 
print Enter a command (1 = North, 2 = East, 3 = South, 4 = 
 
 West, 5 = Exit):
 
if int(raw_input()) == 1:
 
 
 
 You're asking the user to enter something and then checking whether its 
 
 int value is 1.
 
 
 
print Moving north
 
y = y + 1
 
elif int(raw_input()) == 2:
 
 
 
 Now you're asking the user to enter something _again_ and then checking 
 
 whether its int value is 2.
 
 
 
 In other words, in order for it to print Moving east the following 
 
 steps must occur:
 
 
 
 1. Ask the user to enter something.
 
 
 
 2. Check whether it's 1. It isn't. (Previous condition)
 
 
 
 3. Ask the user to enter something.
 
 
 
 4. Check whether it's 2. (This condition)
 
 
 
print Moving east
 
x = x + 1
 
elif int(raw_input()) == 3:
 
 
 
 Similar remarks to above, but longer.
 
 
 
print Moving south
 
y = y - 1
 
elif int(raw_input()) == 4:
 
 
 
 Similar remarks to above, but longer again.
 
 
 
print Moving west
 
x = x - 1
 
elif int(raw_input()) == 5:
 
 
 
 Similar remarks to above, but longer again.
 
 
 
print Dost thou leave so soon? Fare thee well!
 
quitCommand = 5
 
else:
 
print I find your lack of reading comprehension skills 
 
 disturbing.
 
  
 
 
 
 The fix is simple. Ask once:
 
 
 
   answer = int(raw_input())
 
   if answer == 1:
 
   ...
 
   elif answer == 2:
 
   ...
 
   ...

Thanks a lot! I'll try this out!
Sorry to everyone else whose eyes I made bleed. I've never used a newsgroup 
before...still not really sure what they are. Found this through a google 
search :\
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New user's initial thoughts / criticisms of Python

2013-11-12 Thread Ethan Furman

On 11/11/2013 06:05 PM, Dennis Lee Bieber wrote:

On Mon, 11 Nov 2013 09:01:07 -0500, Roy Smith r...@panix.com declaimed the
following:



Ugh, what's this close paren?  Does it terminate the get(), or the
print()?  I need to go back and count open parens to make sure


No... You need to use an editor/IDE that will highlight the matching
parens for you...


I have one of those, and I still sometimes miss one.  :/

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


Re: To whoever hacked into my Database

2013-11-12 Thread Antoon Pardon
Op 12-11-13 12:23, Ned Batchelder schreef:
 On Tuesday, November 12, 2013 1:31:32 AM UTC-5, ru...@yahoo.com wrote:
 On 11/11/2013 06:16 PM, Ned Batchelder wrote:
 Nikos has received a good deal of genuine advice.  He has also been
 genuinely difficult to help.

 Yes.  If he is too difficult to help without getting
 angry because he won't do what you (generic) tell him
 then perhaps a more constructive response is to stop
 trying to help him rather than join the lynch mob that
 is making the atmosphere here far worse (IMO) than
 Nikos alone could.
 
 I absolutely agree with this.

This ignores the contribution of the spoon feeders. The frustration
originates with seeing Nikos ignoring helpful advices and repeating
the same question. So stop trying to help, doesn't deminish the
frustration in a significant way as long as the spoon feeders continue
to motivate Nikos in this kind of behaviour.

As long as the spoon feeders are allowed to contribute to the frustration
of other group members, you will have people who feel they are justified
in venting their frustration in the news group. And only taking the
venters to task while ignoring the spoon feeders will mostly result in
not be taken serious and will produce rather bad will than good will to
your goal.

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


Re: Basic Python Questions - Oct. 31, 2013

2013-11-12 Thread Chris Angelico
On Tue, Nov 12, 2013 at 9:21 PM, E.D.G. edgrs...@ix.netcom.com wrote:
   The point is, when people want to make some computer program available
 for use by others around the world they might want to circulate a version of
 their program that has such a simple format that anyone can understand it.
 And for actual use they can generate parallel versions that have more
 efficient code that people who are working with that language can
 understand.

Sounds to me like something out of cryptography. You have a reference
implementation that's slow, readable, and straight-forward, and then
you have optimized implementations that are actually fast enough to
use - but if any time you want to know if you're producing the right
output, you just compare against the reference implementation.

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


Re: Stop feeding the Ferrous Cranus troll

2013-11-12 Thread Petite Abeille

On Nov 12, 2013, at 2:16 AM, Chuck Quast quast...@gmail.com wrote:

 why are any of you replying?

A Group Is Its Own Worst Enemy” — Clay Shirky, 2003
http://www.shirky.com/writings/herecomeseverybody/group_enemy.html

More practically:

Help Vampires: A Spotter’s Guide” — Amy Hoy, 2006
http://slash7.com/2006/12/22/vampires/ 

A Taxonomy of Help Vampires
http://jasonwryan.com/blog/2012/03/17/vampires/

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


Re: 'isimmutable' and 'ImmutableNester'

2013-11-12 Thread Mark Lawrence

On 12/11/2013 11:10, Frank-Rene Schäfer wrote:


Admittedly, I have no knowledge about the python implementation.



There is no the regarding Python implementations.  Cpython alone is at 
either 2.7.6 or 3.3.3 with 3.4 at alpha, then there's IronPython, 
Jython, PyPy and lots more that I'm sure Steven D'Aprano can probably 
list from the top of his head :)


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: Some python newb help please?

2013-11-12 Thread Denis McMahon
On Tue, 12 Nov 2013 14:14:42 -0800, lrwarren94 wrote:

 http://pastebin.com/6QZTvx6Z

Work through your code very very carefully. You're doing something in 
each if branch that you probably only want to do once in each execution 
of the while loop.

If you can't figure it out, I'll post a corrected version next week.

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


Re: using print() with multiprocessing and pythonw

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 7:22 AM, Isaac Gerg isaac.g...@gergltd.com wrote:
 Thanks for the reply Bill.  The problem is the text i am getting is from a 
 python warning message, not one of my own print() function calls.

Since sys.stdout is just an object, you could replace it with
something that redirects its write() calls to the logging function.
Might be a bit hacky, but it should work.

BTW, sys.executable.find('pythonw') =0 should be able to be spelled
'pythonw' in sys.executable.

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


Re: [Python-Dev] The pysandbox project is broken

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 8:16 AM, Victor Stinner
victor.stin...@gmail.com wrote:
 In 2010, a developper called Tav wrote a sandbox called safelite.py:
 the sandbox hides sensitive attributes to separate a trusted namespace
 and an untrusted namespace.

Ha, I come full circle. This was the exact project that brought me to
this list (for better or for worse!), as we were trying to sandbox
Python code inside C++. Same sort of thing - we wanted free access to
whatever it could do in memory, but no FS or OS access (and limits on
total memory and CPU usage, though they're less critical as I can use
OS APIs to do that). Conclusion: Either utterly impossible, or so hard
as to be not worth the hassle. We switched to JavaScript, though I do
maintain some regret that we couldn't use the better language.

It's probably too late for that project to switch back now (and I've
left the company), but as a matter of intellectual curiosity, I'm
still somewhat interested.

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


Re: Some python newb help please?

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 10:04 AM,  lrwarre...@gmail.com wrote:
 Thanks a lot! I'll try this out!
 Sorry to everyone else whose eyes I made bleed. I've never used a newsgroup 
 before...still not really sure what they are. Found this through a google 
 search :\

There's an easy fix. Go to this page:

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

You can then subscribe to the mailing list using whatever email
address you're comfortable with. I use Gmail, which works fairly well
but has its own issues; I've glanced at Evolution (a Linux mail
client) and its way of handling threads, and it seems to do a good
job. Plenty of options.

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


Re: To whoever hacked into my Database

2013-11-12 Thread Mark Lawrence

On 12/11/2013 17:22, Antoon Pardon wrote:

Op 12-11-13 12:23, Ned Batchelder schreef:

On Tuesday, November 12, 2013 1:31:32 AM UTC-5, ru...@yahoo.com wrote:

On 11/11/2013 06:16 PM, Ned Batchelder wrote:

Nikos has received a good deal of genuine advice.  He has also been
genuinely difficult to help.


Yes.  If he is too difficult to help without getting
angry because he won't do what you (generic) tell him
then perhaps a more constructive response is to stop
trying to help him rather than join the lynch mob that
is making the atmosphere here far worse (IMO) than
Nikos alone could.


I absolutely agree with this.


This ignores the contribution of the spoon feeders. The frustration
originates with seeing Nikos ignoring helpful advices and repeating
the same question. So stop trying to help, doesn't deminish the
frustration in a significant way as long as the spoon feeders continue
to motivate Nikos in this kind of behaviour.

As long as the spoon feeders are allowed to contribute to the frustration
of other group members, you will have people who feel they are justified
in venting their frustration in the news group. And only taking the
venters to task while ignoring the spoon feeders will mostly result in
not be taken serious and will produce rather bad will than good will to
your goal.



I'm 100% behind you with this.  Sadly the message just doesn't seem to 
get across so I suggest that we talk to brick walls, at least we'll not 
expect a response of any kind.


--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


Re: To whoever hacked into my Database

2013-11-12 Thread Ian Kelly
On Tue, Nov 12, 2013 at 2:59 PM, Ethan Furman et...@stoneleaf.us wrote:
 Every time he uses foul language against somebody he's acting like a bully.

 Every time he reposts questions and ignores answers he's acting like a
 bully.

 Every time he declares that what he wants is the most important and so he is
 going to ignore our culture and the topic of this forum/ml/ng he is acting
 like a bully.

 If you haven't seen those posts, I have.  Now you know.

Per Wikipedia: Bullying is the use of force, threat, or coercion to
abuse, intimidate, or aggressively to impose domination over others.
... One essential prerequisite is the perception, by the bully or by
others, of an imbalance of social or physical power.

None of the behaviors that you cite are examples of bullying.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: To whoever hacked into my Database

2013-11-12 Thread Mark Lawrence

On 12/11/2013 23:27, Ian Kelly wrote:

On Tue, Nov 12, 2013 at 2:59 PM, Ethan Furman et...@stoneleaf.us wrote:

Every time he uses foul language against somebody he's acting like a bully.

Every time he reposts questions and ignores answers he's acting like a
bully.

Every time he declares that what he wants is the most important and so he is
going to ignore our culture and the topic of this forum/ml/ng he is acting
like a bully.

If you haven't seen those posts, I have.  Now you know.


Per Wikipedia: Bullying is the use of force, threat, or coercion to
abuse, intimidate, or aggressively to impose domination over others.
... One essential prerequisite is the perception, by the bully or by
others, of an imbalance of social or physical power.

None of the behaviors that you cite are examples of bullying.



What would you classify insulting my late mother as?

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


  1   2   >