Vote tallying...

2013-01-18 Thread Andrew Robinson

Hi,

I have a problem which may fit in a mysql database, but which I only 
have python as an alternate tool to solve... so I'd like to hear some 
opinions...


I'm building a experimental content management program on a standard 
Linux Web server.
And I'm needing to keep track of archived votes and their voters -- for 
years.


Periodically, a python program could be given a batch of new votes 
removed from the database, and some associated comments, which are no 
longer real-time necessary;  and then a python script needs to take that 
batch of votes, and apply them to an appropriate archive file.  It's 
important to note that it won't just be appending new votes, it will be 
sorting through a list of 10's of thousands of votes, and changing a 
*few* of them, and appending the rest.


XML may not be the ideal solution, but I am easily able to see how it 
might work.  I imagine a file like the following might be inefficient, 
but capable of solving the problem:





   
   12345A3
   FF734B5D
   7FBED
   The woodstock games



I think you're on 
drugs, man.!
It would have been 
better if they didn't wake up in the morning.




10
1
3



The questions I have are, is using XML for vote recording going to be 
slow compared to other stock solutions that Python may have to offer?  
The voter ID's are unique, 32 bits long, and the votes are only from 1 
to 10. (4 bits.).  I'm free to use any import that comes with python 
2.5. so if there's something better than XML, I'm interested.


And secondly, how likely is this to still work once the vote count 
reaches 10 million?
Is an XML file with millions of entries something someone has already 
tried succesfully?



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


Re: Vote tallying...

2013-01-18 Thread Lie Ryan

On 18/01/13 10:59, Andrew Robinson wrote:

Hi,

I have a problem which may fit in a mysql database, but which I only
have python as an alternate tool to solve... so I'd like to hear some
opinions...


Since you have a large dataset, you might want to use sqlite3 
(http://docs.python.org/2.5/lib/module-sqlite3.html, 
https://www.sqlite.org/), which comes in the standard library since 
Python 2.5. SQLite is a self-contained, serverless, zero configuration, 
transactional SQL database engine.


XML with a million entries are probably not a good idea due to its 
verbosity; XML was designed for data interchange, not for complex 
relational data processing.


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


Re: Vote tallying...

2013-01-18 Thread Stefan Behnel
Andrew Robinson, 18.01.2013 00:59:
> I have a problem which may fit in a mysql database

Everything fits in a MySQL database - not a reason to use it, though. Py2.5
and later ship with sqlite3 and if you go for an external database, why use
MySQL if you can have PostgreSQL for the same price?


> but which I only have
> python as an alternate tool to solve... so I'd like to hear some opinions...
> 
> I'm building a experimental content management program on a standard Linux
> Web server.
> And I'm needing to keep track of archived votes and their voters -- for years.
> 
> Periodically, a python program could be given a batch of new votes removed
> from the database, and some associated comments, which are no longer
> real-time necessary;  and then a python script needs to take that batch of
> votes, and apply them to an appropriate archive file.  It's important to
> note that it won't just be appending new votes, it will be sorting through
> a list of 10's of thousands of votes, and changing a *few* of them, and
> appending the rest.
> 
> XML may not be the ideal solution, but I am easily able to see how it might
> work.  I imagine a file like the following might be inefficient, but
> capable of solving the problem:
> 
> 
> 
> 
>
>12345A3
>FF734B5D
>7FBED
>The woodstock games
> 
> 
> 
> I think you're on drugs,
> man.!
> It would have been
> better if they didn't wake up in the morning.
> 
> 
> 
> 10
> 1
> 3
> 
> 
> 
> The questions I have are, is using XML for vote recording going to be slow
> compared to other stock solutions that Python may have to offer?  The voter
> ID's are unique, 32 bits long, and the votes are only from 1 to 10. (4
> bits.).  I'm free to use any import that comes with python 2.5. so if
> there's something better than XML, I'm interested.
> 
> And secondly, how likely is this to still work once the vote count reaches
> 10 million?
> Is an XML file with millions of entries something someone has already tried
> succesfully?

Sure. However, XML files are a rather static thing and meant to be
processed from start to end on each run. That adds up if the changes are
small and local while the file is ever growing. You seem to propose one
file per article, which might work. That's unlikely to become too huge to
process, and Python's cElementTree is a very fast XML processor.

However, your problem sounds a lot like you could map it to one of the dbm
databases that Python ships. They work like dicts, just on disk.

IIUC, you want to keep track of comments and their associated votes, maybe
also keep a top-N list of the highest voted comments. So, keep each comment
and its votes in a dbm record, referenced by the comment's ID (which, I
assume, you keep a list of in the article that it comments on). You can use
pickle (see the shelve module) or JSON or whatever you like for storing
that record. Then, on each votes update, look up the comment, change its
votes and store it back. If you keep a top-N list for an article, update it
at the same time. Consider storing it either as part of the article or in
another record referenced by the article, depending of how you normally
access it. You can also store the votes independent of the comment (i.e. in
a separate record for each comment), in case you don't normally care about
the votes but read the comments frequently. It's just a matter of adding an
indirection for things that you use less frequently and/or that you use in
more than one place (not in your case, where comments and votes are unique
to an article).

You see, lots of options, even just using the stdlib...

Stefan


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


Re: Loading a PKCS#1 public key using M2Crypto

2013-01-18 Thread Marc Aymerich
On Fri, Jan 18, 2013 at 12:10 AM, Piet van Oostrum  wrote:
> Marc Aymerich  writes:
>
>> Thank you very much Piet,
>> I'm just starting to grasp these cryptography related concepts and your code 
>> is helping me a lot to understand how to handle these keys in a low level.
>>
>> I'm updating my code incorporating your new contribution!
>>
>> Just to let you know, during my previous research I had found a 
>> python-Crypto related solution that also uses DER and ASN.1 [1], but it uses 
>> a different approach (I guess). I suspect that this approach is also 
>> possible with M2Crypto because it has a method for constructing RSA keys [2].
>>
>> [1] http://stackoverflow.com/a/10574723
>> [2] 
>> http://www.heikkitoivonen.net/m2crypto/api/M2Crypto.RSA-module.html#new_pub_key
>>
> new_pub_key could be used but then you would have to do an ASN.1 parse
> of the DER format of your key to get the n and e values. AFAICT M2Crypto
> doesn't have methods to do this, so you would need to use one of the
> python ASN.1 libraries (or write that part yourself).

Thanks for the clarifications,

Just sharing the document I'm reading right now, in case anyone found
this thread and want to know more about ASN.1 and DER:

ftp://ftp.rsasecurity.com/pub/pkcs/ascii/layman.asc

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


Re: Param decorator - can you suggest improvements

2013-01-18 Thread Steven D'Aprano
On Fri, 18 Jan 2013 03:38:08 +, Dan Sommers wrote:

> On Thu, 17 Jan 2013 15:21:08 +, Steven D'Aprano wrote:
> 
>> On Thu, 17 Jan 2013 06:35:29 -0800, Mark Carter wrote:
>> 
>>> I thought it would be interesting to try to implement Scheme SRFI 39
>>> (Parameter objects) in Python.
>>> 
>>> The idea is that you define a function that returns a default value.
>>> If you call that function with no arguments, it returns the current
>>> default. If you call it with an argument, it resets the default to the
>>> value passed in. Here's a working implementation:
>> [...]
>>> Can anyone suggest a better implementation?
>> 
>> I don't like the decorator version, because it requires creating a do-
>> nothing function that just gets thrown away. He's my version, a factory
>> function that takes two arguments, the default value and an optional
>> function name, and returns a Param function: [...]
> 
> This, or something like this, is very old:
> 
> sentinel = object()
> class Magic:
> def __init__(self, value):
> self.value = value
> def __call__(self, value=sentinel):
> if value != sentinel:
> self.value = value
> return self.value

There's not really any magic in that :-)

Better to use "if value is not sentinel" rather than != because the 
caller might provide a custom object that compares equal to sentinel.

Also you should name it SENTINEL, or even _SENTINEL, to indicate that it 
is (1) a constant, and (2) a private variable.


> It's not a function, nor a decorator, but it behaves like a function.

A callable, so-called because you can call it :-)

I believe that C++ calls it a "functor", not to be confused with what 
Haskell calls a functor, which is completely different.



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


Re: Weirdness with python and stdin redirection under Win32

2013-01-18 Thread dexter . rao19
On Saturday, December 7, 2002 5:10:07 AM UTC+5:30, Jonathan M. Gilligan wrote:
> The bug is NOT fixed in Win2k. That's where I am seeing it (Win2K Pro SP3).
> 
> Jonathan
> 
> "Thomas Heller"  wrote in message
> news:fzteezlp@python.net...
> > norbert.klam...@klamann-software.de (Norbert Klamann) writes:
> > > If I remember correctly this is a Windows bug, it was mentioned
> sometimes on this
> > > list.
> > >
> > Right, but it is fixed in Win2k (and hopefully also on XP).
> >
> > Thomas


Guys,

I am trying my hands on Python, and i bump into an error and woah! when you 
google it up, it's an bug in windows.

The bug which you people are discussing about is still not patched up in 
Win XP. I have updated all the my windows update and have installed all kinds 
of patch. 

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


Any built-in ishashable method ?

2013-01-18 Thread Jean-Michel Pichavant
Hello people,

Is there any built-in way to know if an object is a valid dictionary key ? From 
what I know, the object must be hashable, and from the python doc, an object is 
hashable if it has the __hash__ and (__cmp__ or __eq__) methods.

http://docs.python.org/2/glossary.html#term-hashable

I found this on the net, but considering the above definition, does it really 
check the cmp/eq existence ?

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

I was trying to know if any custom class can be used as a dict key. It looks 
like you can. Yet I'm a little bit concerned, because last time I used invalid 
objects as keys, I got a bug that was really difficult to spot.

Regards,

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any built-in ishashable method ?

2013-01-18 Thread Dave Angel

On 01/18/2013 05:36 AM, Jean-Michel Pichavant wrote:

Hello people,

Is there any built-in way to know if an object is a valid dictionary key ? From 
what I know, the object must be hashable, and from the python doc, an object is 
hashable if it has the __hash__ and (__cmp__ or __eq__) methods.

http://docs.python.org/2/glossary.html#term-hashable

I found this on the net, but considering the above definition, does it really 
check the cmp/eq existence ?

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

I was trying to know if any custom class can be used as a dict key. It looks 
like you can. Yet I'm a little bit concerned, because last time I used invalid 
objects as keys, I got a bug that was really difficult to spot.



Yes, one can write custom classes whose objects may be used a dict key. 
 The main conceptual requirement is the object be conceptually 
immutable.  The way the class author indicates that is to define the two 
methods, __hash__() and __eq__().  (or __cmp__() I suppose)


To avoid bugs, there are obviously some constraints on the semantics of 
those methods.  Main ones are 1) that the hash value should not change 
over time, and 2) that if two instances are equal at one moment, that 
they stay so, and vice versa.




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


Re: Any built-in ishashable method ?

2013-01-18 Thread Peter Otten
Jean-Michel Pichavant wrote:

> Hello people,
> 
> Is there any built-in way to know if an object is a valid dictionary key ?
> From what I know, the object must be hashable, and from the python doc, an
> object is hashable if it has the __hash__ and (__cmp__ or __eq__) methods.
> 
> http://docs.python.org/2/glossary.html#term-hashable
> 
> I found this on the net, but considering the above definition, does it
> really check the cmp/eq existence ?
> 
> def ishashable(x):
> try:
> hash(x)
> except TypeError:
> return False
> else:
> return True
> 
> I was trying to know if any custom class can be used as a dict key. It
> looks like you can. Yet I'm a little bit concerned, because last time I
> used invalid objects as keys, I got a bug that was really difficult to
> spot.

Hm, but trying to put an unhashable key into a dict gives the obvious 
exception:

>>> class A(object):
... __hash__ = None
... 
>>> {A(): 42}
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unhashable type: 'A'

So I'm guessing you had a key where

key1 == key2 did not imply hash(key1) == hash(key2)

I don't see a way to avoid that problem in a look-before-you-leap test.

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


Re: Any built-in ishashable method ?

2013-01-18 Thread Terry Reedy

On 1/18/2013 5:36 AM, Jean-Michel Pichavant wrote:

Hello people,

Is there any built-in way to know if an object is a valid dictionary key ?


For the instances of a class to be properly useable as set members or 
dict keys, __eq__ must return bool, __hash__ must return int, the __eq__ 
and __hash__ methods must define equivalence relations on the instances 
of the class, and the hash relation should be a coarsening of the eq 
relation. By default, for objects()s, equality is identity and hash is 
id, so these condition are met.


If the instances of a class can compare equal to instances of another 
class then apply the , then apply the above to the union of the classes 
if they are used together in one set or dict.


An example of when the union condition was broken. We had 0.0 == 0 and 
== decimal(0) but 0.0 != decimal(0). The breaking of transitivity of == 
has nasty effects when mixing floats, ints, and decimals in one 
set/class. (This is fixed now.) For one thing, set((0, 0.0, decimal(0))) 
had one member while set((0.0, 0, decimal(0))) had two ;-)



I was trying to know if any custom class can be used as a dict key.


Yes, unless the __eq__ and __hash__ methods have been over-written in 
the inheritance chain in a way that violates the conditions, or if the 
class instances are mixed with other class instances that joint violate 
the conditions.


> Yet I'm a little bit concerned, because last time I used invalid
> objects as keys, I got a bug that was really difficult to spot.

Yeh, see the example above ;-).

--
Terry Jan Reedy

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


Re: Any built-in ishashable method ?

2013-01-18 Thread Jean-Michel Pichavant
 
> So I'm guessing you had a key where
> 
> key1 == key2 did not imply hash(key1) == hash(key2)
> 
> I don't see a way to avoid that problem in a look-before-you-leap
> test.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

You guessed right. But it took me a lot of time before jumping to that 
conclusion, mostly because the code worked in the first place (it can with a 
little bit of luck).
Now I'm extra careful about what I use as dict key, I was just wondering if 
there was a reliable quick way to verify an object can be used as key.

That brings me to another question, is there any valid test case where key1 != 
key2 and hash(key1) == hash(key2) ? Or is it some kind of design flaw ?

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any built-in ishashable method ?

2013-01-18 Thread Peter Otten
Jean-Michel Pichavant wrote:

> That brings me to another question, is there any valid test case where
> key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design
> flaw ?

I don't think there is a use case for such a behaviour other than annoying 
your collegues ;)

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


Re: Any built-in ishashable method ?

2013-01-18 Thread Steven D'Aprano
On Fri, 18 Jan 2013 12:56:09 +0100, Jean-Michel Pichavant wrote:

>> So I'm guessing you had a key where
>> 
>> key1 == key2 did not imply hash(key1) == hash(key2)
>> 
>> I don't see a way to avoid that problem in a look-before-you-leap test.
>> 
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>> 
>> 
> You guessed right. But it took me a lot of time before jumping to that
> conclusion, mostly because the code worked in the first place (it can
> with a little bit of luck). Now I'm extra careful about what I use as
> dict key, I was just wondering if there was a reliable quick way to
> verify an object can be used as key.

No. You can verify that an object is hashable, by trying to hash it, but 
there is no quick way to verify that the object's hash method isn't buggy.


> That brings me to another question, is there any valid test case where
> key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design
> flaw ?

Neither. It is a consequence of the nature of the universe: the 
Pigeonhole Principle. You can't put N+1 pigeons into N pigeonholes 
without at least one pigeonhole containing two pigeons.

Take, for example, ints. There are an infinite number of possible ints in 
Python, or at least limited only by memory. But there are only a finite 
number of values they can be hashed to: hash values are limited to the 
values -2147483648 through 2147483647 in Python 2.7. You can't have an 
infinite set of values hash to a finite number of hashes without there 
being some duplicates. And so we have:

py> hash(1)
1
py> hash(2**32)
1
py> hash(2**64)
1
py> hash(2**128)
1
py> hash(2**2048)
1


etc. Likewise, there are an infinite number of potential strings, which 
must hash into a finite number of hash values. Although it is hard for me 
to find hash collisions, I know that there must be some, because there 
are more strings than hash values. This is not a design flaw in the hash 
function, and can't be fixed by finding a more clever hash function. Nor 
is it a deliberate feature. It's just the way hashing works.



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


Re: Any built-in ishashable method ?

2013-01-18 Thread Christian Heimes
Am 18.01.2013 12:56, schrieb Jean-Michel Pichavant:
> You guessed right. But it took me a lot of time before jumping to that 
> conclusion, mostly because the code worked in the first place (it can with a 
> little bit of luck).
> Now I'm extra careful about what I use as dict key, I was just wondering if 
> there was a reliable quick way to verify an object can be used as key.
> 
> That brings me to another question, is there any valid test case where key1 
> != key2 and hash(key1) == hash(key2) ? Or is it some kind of design flaw ?

That's a valid case. Hashing is not a permutation, it's (usually)
surjective, not bijective. hash(key1) == hash(key2) is called a "hash
collision".

A good hashing algorithm should try to reduce the probability of
collisions for likely keys. A secure algorithm should also make it as
hard as possible to calculate deliberate collision. Collisions diminish
the efficiency of a hash map from O(1) to O(n) and can be used for
denial of service attacks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any built-in ishashable method ?

2013-01-18 Thread Terry Reedy

On 1/18/2013 6:56 AM, Jean-Michel Pichavant wrote:

is there any valid test case


You mean use case?


where key1 != key2 and hash(key1) == hash(key2) ?


This is the normal case. There are many unequal items that have the same 
hash. The point of using hash is to quickly find items in the set/dict 
that *might* be equal to the candidate item, and to place items where 
they can be easily found. The alternative is a unordered list and a 
linear O(n) search, or a sorted list and a bisecting O(log(n)) search. 
(The latter is quite useful when one is doing insertion sort for small N 
or the list is static (or mostly so) and one want to know which items in 
the list bracket a candidate item that is not in the list.)


The rule is key==key implies hash==hash, which is equivalent to hash != 
hash implies key != key.


Reference 3.3 object.__hash__ "The only required property is that 
objects which compare equal have the same hash value;"



Or is it some kind of design flaw ?


The flaw would be key1 == key2 and hash(key1) != hash(key2). Then the 
set/dict could store equal items multiple times in different places 
(unless it did a linear search of all members, which would make hashing 
pointless!).


--
Terry Jan Reedy

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


Re: Forcing Python to detect DocumentRoot

2013-01-18 Thread Ferrous Cranus
Τη Πέμπτη, 17 Ιανουαρίου 2013 5:14:19 μ.μ. UTC+2, ο χρήστης Joel Goldstick 
έγραψε:
> On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith  wrote:
> 
> In article <339d9d6d-b000-4cf3-8534-375e0c44b...@googlegroups.com>,
> 
> 
> 
>  Ferrous Cranus  wrote:
> 
> 
> 
> > When trying to open an html template within Python script i use a relative
> 
> > path to say go one folder back and open index.html
> 
> >
> 
> > f = open( '../' + page )
> 
> >
> 
> > How to say the same thing in an absolute way by forcing Python to detect
> 
> > DocumentRoot by itself?
> 
> 
> 
> Can you give us more details of what you're doing.  Is there some web
> 
> framework you're using?  Can you post some code that's not working for
> 
> you?
> 
> --
> 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> Import os
> 
> Then read os.environ['HOME']
> 
> 
> This will give you the home directory of the user.  in my case:
> 
> 
> >>> os.environ['HOME']
> '/home/jcg'
> >>> 
> 
> 
> This is probably linux only, but that seems to be the environment you are 
> working in .

Yes my Python scripts exist in a linux web host.

os.environ['HOME'] will indeed give the home directory of the user.

to me /home/nikos/

but i want a variable to point to

/home/nikos/public_html whice is called DocumentRoot.

is there avariable for that? i can't seem to find any...
-- 
http://mail.python.org/mailman/listinfo/python-list


Inconsistent behaviour of methods waiting for child process

2013-01-18 Thread Marcin Szewczyk
Hi,

I've done some experiments with:
1) multiprocessing.Process.join()
2) os.waitpid()
3) subprocess.Popen.wait()

These three methods behave completely different when interrupted with a
signal which I find disturbing.

Reactions are:
1) exit with no exception or special return code
2) OSError exception
3) quiet retry (no exit)

The 1) case is very impractical.

Is there any movement towards standardization of those 3?

Am I missing something and there is a way to get more information from
Process.join()?

-- 
Marcin Szewczyk   http://wodny.org
mailto:marcin.szewc...@wodny.borg  <- remove b / usuń b
xmpp:wo...@ubuntu.pl  xmpp:wo...@jabster.pl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Forcing Python to detect DocumentRoot

2013-01-18 Thread Joel Goldstick
On Fri, Jan 18, 2013 at 8:02 AM, Ferrous Cranus wrote:

> Τη Πέμπτη, 17 Ιανουαρίου 2013 5:14:19 μ.μ. UTC+2, ο χρήστης Joel Goldstick
> έγραψε:
> > On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith  wrote:
> >
> > In article <339d9d6d-b000-4cf3-8534-375e0c44b...@googlegroups.com>,
> >
> >
> >
> >  Ferrous Cranus  wrote:
> >
> >
> >
> > > When trying to open an html template within Python script i use a
> relative
> >
> > > path to say go one folder back and open index.html
> >
> > >
> >
> > > f = open( '../' + page )
> >
> > >
> >
> > > How to say the same thing in an absolute way by forcing Python to
> detect
> >
> > > DocumentRoot by itself?
> >
> >
> >
> > Can you give us more details of what you're doing.  Is there some web
> >
> > framework you're using?  Can you post some code that's not working for
> >
> > you?
> >
> > --
> >
> > http://mail.python.org/mailman/listinfo/python-list
> >
> >
> >
> > Import os
> >
> > Then read os.environ['HOME']
> >
> >
> > This will give you the home directory of the user.  in my case:
> >
> >
> > >>> os.environ['HOME']
> > '/home/jcg'
> > >>>
> >
> >
> > This is probably linux only, but that seems to be the environment you
> are working in .
>
> Yes my Python scripts exist in a linux web host.
>
> os.environ['HOME'] will indeed give the home directory of the user.
>
> to me /home/nikos/
>
> but i want a variable to point to
>
> /home/nikos/public_html whice is called DocumentRoot.
>
> is there avariable for that? i can't seem to find any...
> --
> http://mail.python.org/mailman/listinfo/python-list
>


DocumentRoot = os.environ['HOME'] + 'public_html'
-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Forcing Python to detect DocumentRoot

2013-01-18 Thread Rodrick Brown
On Friday, January 18, 2013, Ferrous Cranus wrote:

> Τη Πέμπτη, 17 Ιανουαρίου 2013 5:14:19 μ.μ. UTC+2, ο χρήστης Joel Goldstick
> έγραψε:
> > On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith >
> wrote:
> >
> > In article 
> > <339d9d6d-b000-4cf3-8534-375e0c44b...@googlegroups.com
> >,
> >
> >
> >
> >  Ferrous Cranus > wrote:
> >
> >
> >
> > > When trying to open an html template within Python script i use a
> relative
> >
> > > path to say go one folder back and open index.html
> >
> > >
> >
> > > f = open( '../' + page )
> >
> > >
> >
> > > How to say the same thing in an absolute way by forcing Python to
> detect
> >
> > > DocumentRoot by itself?
> >


$ export DOCUMENT_ROOT=${HOME}/public _html

Then from python os.environ['DOCUMENT_ROOT'] will have the relative path.

I hope this helps.


> >
> >
> > Can you give us more details of what you're doing.  Is there some web
> >
> > framework you're using?  Can you post some code that's not working for
> >
> > you?
> >
> > --
> >
> > http://mail.python.org/mailman/listinfo/python-list
> >
> >
> >
> > Import os
> >
> > Then read os.environ['HOME']
> >
> >
> > This will give you the home directory of the user.  in my case:
> >
> >
> > >>> os.environ['HOME']
> > '/home/jcg'
> > >>>
> >
> >
> > This is probably linux only, but that seems to be the environment you
> are working in .
>
> Yes my Python scripts exist in a linux web host.
>
> os.environ['HOME'] will indeed give the home directory of the user.
>
> to me /home/nikos/
>
> but i want a variable to point to
>
> /home/nikos/public_html whice is called DocumentRoot.
>
> is there avariable for that? i can't seem to find any...
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inconsistent behaviour of methods waiting for child process

2013-01-18 Thread Matt Jones
What version of python and os are you running?

*Matt Jones*


On Fri, Jan 18, 2013 at 6:04 AM, Marcin Szewczyk wrote:

> Hi,
>
> I've done some experiments with:
> 1) multiprocessing.Process.join()
> 2) os.waitpid()
> 3) subprocess.Popen.wait()
>
> These three methods behave completely different when interrupted with a
> signal which I find disturbing.
>
> Reactions are:
> 1) exit with no exception or special return code
> 2) OSError exception
> 3) quiet retry (no exit)
>
> The 1) case is very impractical.
>
> Is there any movement towards standardization of those 3?
>
> Am I missing something and there is a way to get more information from
> Process.join()?
>
> --
> Marcin Szewczyk   http://wodny.org
> mailto:marcin.szewc...@wodny.borg  <- remove b / usuń b
> xmpp:wo...@ubuntu.pl  xmpp:wo...@jabster.pl
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any built-in ishashable method ?

2013-01-18 Thread Jean-Michel Pichavant
> The flaw would be key1 == key2 and hash(key1) != hash(key2). Then the
> set/dict could store equal items multiple times in different places
> (unless it did a linear search of all members, which would make
> hashing
> pointless!).
> 
> --
> Terry Jan Reedy

My understanding of a hash function was wrong in the first place.
Thank to this thread, I think I got it right now.

Thanks to all who have contributed, (and those who haven't, yes, I'm in a good 
mood now).

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inconsistent behaviour of methods waiting for child process

2013-01-18 Thread Marcin Szewczyk
On Fri, Jan 18, 2013 at 08:10:03AM -0600, Matt Jones wrote:
> What version of python and os are you running?

$ python --version
Python 2.7.3rc2

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:Debian GNU/Linux 7.0 (wheezy)
Release:7.0
Codename:   wheezy

$ uname -a
Linux magazyn-ziarno 3.2.0-4-686-pae #1 SMP Debian 3.2.35-2 i686 GNU/Linux

-- 
Marcin Szewczyk   http://wodny.org
mailto:marcin.szewc...@wodny.borg  <- remove b / usuń b
xmpp:wo...@ubuntu.pl  xmpp:wo...@jabster.pl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Param decorator - can you suggest improvements

2013-01-18 Thread Dan Sommers
On Fri, 18 Jan 2013 09:10:34 +, Steven D'Aprano wrote:

> On Fri, 18 Jan 2013 03:38:08 +, Dan Sommers wrote:

>> This, or something like this, is very old:
>> 
>> sentinel = object()
>> class Magic:
>> def __init__(self, value):
>> self.value = value
>> def __call__(self, value=sentinel):
>> if value != sentinel:
>> self.value = value
>> return self.value
> 
> There's not really any magic in that :-)

Well, not any more, no, but this one has stuck in my mind because of the 
magic it revealed the first time I saw it.  It was definitely one of 
those Aha! moments for me.

> Better to use "if value is not sentinel" rather than != because the
> caller might provide a custom object that compares equal to sentinel.
> 
> Also you should name it SENTINEL, or even _SENTINEL, to indicate that it
> is (1) a constant, and (2) a private variable.

Both fair points.

> I believe that C++ calls it a "functor", not to be confused with what
> Haskell calls a functor, which is completely different.

But we like overloaded terminology!  ;-)

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


Beginner Tutorials

2013-01-18 Thread Rik
Hi, I've developed a website for beginners to Python. I'd appreciate any 
comments or criticism. It's still under development, and should be finished in 
the next few months. Oh, and it's free to use.

www.usingpython.com
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Vote tallying...

2013-01-18 Thread Nick Cash
> I have a problem which may fit in a mysql database, but which I only
> have python as an alternate tool to solve... so I'd like to hear some
> opinions...

Is there a reason you can't use an RDBMS for this? MySQL would certainly be 
fine, although I always recommend PostgreSQL over it. Based on the amount of 
data you've specified, you really don't want to be rolling your own data 
storage system. If you absolutely cannot install any new software, Sqllite is 
built into Python and would work almost as well.

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


Re: Beginner Tutorials

2013-01-18 Thread marco . kretz
Am Freitag, 18. Januar 2013 15:47:52 UTC+1 schrieb Rik:
> Hi, I've developed a website for beginners to Python. I'd appreciate any 
> comments or criticism. It's still under development, and should be finished 
> in the next few months. Oh, and it's free to use.
> 
> 
> 
> www.usingpython.com

Very nice and clean structure, I like it!

But I would recommend to place the menu right below the header ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner Tutorials

2013-01-18 Thread Virgil Stokes

On 18-Jan-2013 15:47, Rik wrote:

Hi, I've developed a website for beginners to Python. I'd appreciate any 
comments or criticism. It's still under development, and should be finished in 
the next few months. Oh, and it's free to use.

www.usingpython.com
You have  done well Rik. I like your approach to passwords for solutions and 
your selection of topics is quite good for a "jump start" with Python.  However, 
I suggest that in your menu you change several of your items to lower case (for 
consistency with the Python language):   For -> for, While -> while, if-Else -> 
if-else, Elif -> elif.


I am curious --- what software did you use to create your nice web pages for 
this tutorial?


In summary --- good work Rik :-)

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


Re: Beginner Tutorials

2013-01-18 Thread Joel Goldstick
On Fri, Jan 18, 2013 at 10:52 AM, Virgil Stokes  wrote:

> On 18-Jan-2013 15:47, Rik wrote:
>
>> Hi, I've developed a website for beginners to Python. I'd appreciate any
>> comments or criticism. It's still under development, and should be finished
>> in the next few months. Oh, and it's free to use.
>>
>> www.usingpython.com
>>
> You have  done well Rik. I like your approach to passwords for solutions
> and your selection of topics is quite good for a "jump start" with Python.
>  However, I suggest that in your menu you change several of your items to
> lower case (for consistency with the Python language):   For -> for, While
> -> while, if-Else -> if-else, Elif -> elif.
>
> I am curious --- what software did you use to create your nice web pages
> for this tutorial?
>

I was curious too, since I noticed right click doesn't work on the pages.
So, you use Wordpress and have this plugin:
http://chetangole.com/blog/wp-copyprotect/  .  I am wondering why you think
it is so important that your source code not be viewed?  Of course it can
be viewed with curl or wget or similar methods, just not be a curious
reader who is interested in the underlying html that produced the site.
Messing with the reader's browser is not considered polite by many!

>
> In summary --- good work Rik :-)
>
> --V
> --
> http://mail.python.org/**mailman/listinfo/python-list
>



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


Re: Beginner Tutorials

2013-01-18 Thread Ian Foote

On 18/01/13 14:47, Rik wrote:

Hi, I've developed a website for beginners to Python. I'd appreciate any 
comments or criticism. It's still under development, and should be finished in 
the next few months. Oh, and it's free to use.

www.usingpython.com



Is there a particular reason you disable right-click with javascript?

Regards,
Ian F
--
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner Tutorials

2013-01-18 Thread Ian Foote

On 18/01/13 14:47, Rik wrote:

Hi, I've developed a website for beginners to Python. I'd appreciate any 
comments or criticism. It's still under development, and should be finished in 
the next few months. Oh, and it's free to use.

www.usingpython.com



Your example code on http://usingpython.com/variables/ is missing a space:

#Whatever the user enters is stored in a variable called ‘name’.
name = input("What is your name? ")
# Remember how we can use + to ‘add’ strings together?
print("Hello" + name + "!")

Here's my output:

>>> name = input("What is your name? ")
What is your name? Ian
>>> print("Hello" + name + "!")
HelloIan!

Your final print should be:

print("Hello " + name + "!")

Regards,
Ian F
--
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner Tutorials

2013-01-18 Thread Rik
Thanks for the comments. I have changed the headings to lower case as you 
suggested.
The site was created in wordpress using a standard theme, and linked pages 
rather than posts. i'd recommend using it to quickly set up a site; i started 
developing my own site but wanted to focus on site content and not HTML!

> You have  done well Rik. I like your approach to passwords for solutions and 
> 
> your selection of topics is quite good for a "jump start" with Python.  
> However, 
> 
> I suggest that in your menu you change several of your items to lower case 
> (for 
> 
> consistency with the Python language):   For -> for, While -> while, if-Else 
> -> 
> 
> if-else, Elif -> elif.
> 
> 
> 
> I am curious --- what software did you use to create your nice web pages for 
> 
> this tutorial?
> 
> 
> 
> In summary --- good work Rik :-)
> 
> 
> 
> --V

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


Re: Beginner Tutorials

2013-01-18 Thread Rik
The reason for disabling right-click has nothing to do with protecting content, 
and everything to do with stopping my students from taking the lazy way out.

Given the chance, they'll copy/paste the code and download the designs and edit 
them slightly. They'd get through the tutorials in about 25 minutes and have 
learnt next to nothing.

In talking to students about existing resources, they said that blindly copying 
code didn't really help them get a deep understanding of algorithms and how to 
apply them to other problems.

In the password-protected solutions i will provide downloads to source code, 
etc, and any student smart enough to get around my protection probably 
understands python basics :)

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


Re: Beginner Tutorials

2013-01-18 Thread Rik
Well spotted!

> Your final print should be:
> 
> 
> 
>  print("Hello " + name + "!")
> 
> 
> 
> Regards,
> 
> Ian F

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


Re: Beginner Tutorials

2013-01-18 Thread Ritchie Flick
Still a student myself and even if you really want to become good at what
you're doing, some days one just feels lazy and in the mood for
copy/pasting to get the job done quickly xD
I like the site, will check it out ;)


On Fri, Jan 18, 2013 at 6:34 PM, Joel Goldstick wrote:

>
>
>
> On Fri, Jan 18, 2013 at 12:04 PM, Rik  wrote:
>
>> The reason for disabling right-click has nothing to do with protecting
>> content, and everything to do with stopping my students from taking the
>> lazy way out.
>>
>> Given the chance, they'll copy/paste the code and download the designs
>> and edit them slightly. They'd get through the tutorials in about 25
>> minutes and have learnt next to nothing.
>>
>
> Ha Ha! that is hilarious.  I haven't been a student for a while.  I guess
> I am naive to think that young people would be interested, and take
> pleasure in becoming proficient rather than just a quick way to get a
> better grade.
>
>>
>> In talking to students about existing resources, they said that blindly
>> copying code didn't really help them get a deep understanding of algorithms
>> and how to apply them to other problems.
>>
>> In the password-protected solutions i will provide downloads to source
>> code, etc, and any student smart enough to get around my protection
>> probably understands python basics :)
>>
>> Thanks for the comments.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
>
> --
> Joel Goldstick
> http://joelgoldstick.com
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


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


Re: Forcing Python to detect DocumentRoot

2013-01-18 Thread Ferrous Cranus
Τη Παρασκευή, 18 Ιανουαρίου 2013 3:28:10 μ.μ. UTC+2, ο χρήστης Joel Goldstick 
έγραψε:

> DocumentRoot = os.environ['HOME'] + 'public_html'

Yes, iam using this and it works.
One last thing:

my python script file is located at 
/home/nikos/public_html/addon_domain/cgi-bin/

How python is able to run the following statement?

f = open( '/home/nikos/public_html/' + page )

which is clearly levels up of addon domain's DocumentRoot?
-- 
http://mail.python.org/mailman/listinfo/python-list


Reinforced Concrete: Mechanics and Design (5th Ed., James G. MacGregor & James K. Wight)

2013-01-18 Thread kalvinmanual1
I have solutions manuals to all problems and exercises in these textbooks. To 
get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com 
and let me know its title, author and edition. Please this service is NOT free.

 
solutions manual :: Reinforced Concrete: Mechanics and Design (5th Ed., James 
G. MacGregor & James K. Wight)
solutions manual :: Satellite Communications 2nd Ed By Timothy Pratt, Charles 
W. Bostian
solutions manual :: Scientific Computing with Case Studies by Dianne P. O'Leary
solutions manual :: Semiconductor Device Fundamentals by Pierret
solutions manual :: SEMICONDUCTOR DEVICES Physics and Technology 2nd Ed by SZE
solutions manual :: Semiconductor Physics and Applications by Balkanski, Wallis
solutions manual :: Semiconductor Physics and Devices (3rd Ed., Donald A. 
Neamen)
solutions manual :: Semiconductor Physics and Devices 4th E by Donald A. Neamen
solutions manual :: Separation Process Principles 2nd ED by Seader, Henley
solutions manual :: Separation Process Principles by Seader & Henley
solutions manual :: SERWAY AND VUILLE’S COLLEGE PHYSICS NINTH EDITION
solutions manual :: Shigley's Mechanical Engineering Design (8th Ed., Budynas)
solutions manual :: Signal Processing and Linear Systems by Lathi
solutions manual :: Signal Processing First by Mclellan, Schafer & Yoder
solutions manual :: Signals and Systems 2e by Haykin & B Van Veen
solutions manual :: Signals and Systems 2nd Edition Oppenheim, Willsky and Nawab
solutions manual :: Signals and Systems Analysis of Signals Through Linear 
Systems by M.J. Roberts, M.J. Roberts
solutions manual :: Signals and Systems, 2nd Edition, Oppenheim, Willsky, 
Hamid, Nawab
solutions manual :: Signals and Systems: Analysis Using Transform Methods and 
MATLAB, 1st Ed., by M. J. Roberts
solutions manual :: Signals, Systems & Transforms 3rd ED by Phillips, Parr & 
Riskin
solutions manual :: Signals, Systems & Transforms 4 ED by Phillips, Parr & 
Riskin
solutions manual :: SILICON VLSI TECHNOLOGY Fundamentals, Practice and Modeling 
By Plummer, Griffin 
solutions manual :: Simply C# -  An Application-Driven (TM) Tutorial Approach 
by Deitel
solutions manual :: Single Variable Calculus Early Transcendentals, 4th 
Edition, JAMES STEWART
solutions manual :: Single Variable Calculus Early Transcendentals, 5th 
Edition, JAMES STEWART
solutions manual :: Sipser's Introduction to the Theory of COMPUTATION
solutions manual :: Skill - Assessment Exercises to Accompany Control Systems 
Engineering 3rd edt. by Norman S. Nise
solutions manual :: Skill - Assessment Exercises to Accompany Control Systems 
Engineering 5th edt. by Norman S. Nise
solutions manual :: Soil Mechanics 7th ed by R. F. Craig
solutions manual :: Soil Mechanics Concepts and Applications, 2nd Ed., by Powrie
solutions manual :: Solid State Electronic Devices (6th Ed., Ben Streetman, 
Sanjay Banerjee)
solutions manual :: Solid State Electronics 5th ed by Ben Streetman, Sanjay 
Banerjee
solutions manual :: Solid State Physics by Ashcroft & Mermin
solutions manual :: Solid State Physics by Lazlo Mihaly, Michael C. Martin
solutions manual :: Solving Applied Mathematical Problems with MATLAB by Xue, 
Chen
solutions manual :: Solving ODEs with MATLAB (L. F. Shampine, I. Gladwell & S. 
Thompson)
solutions manual :: South-Western Federal Taxation 2012 -  Corporations, 
Partnerships, Estates and Trusts, 35th Ed by Hoffman, Maloney
solutions manual :: Special Relativity (P.M. Schwarz & J.H. Schwarz)
solutions manual :: Statics and Mechanics of Materials by Bedford, Fowler, 
Liechti
solutions manual :: Statics and Mechanics of Materials, 2/E., By Russell C. 
Hibbeler
solutions manual :: Statistical and Adaptive Signal Processing by Manolakis, 
Ingle, Kogon
solutions manual :: Statistical Digital Signal Processing and Modeling ,Monson 
H. Hayes
solutions manual :: Statistical Inference 2e by Casella G., Berger R.L. and 
Santana
solutions manual :: Statistical Inference, Second Edition Casella-Berger
solutions manual :: Statistical Physics of Fields by Mehran Kardar
solutions manual :: Statistical Physics of Particles by Mehran Kardar
solutions manual :: Statistics and Finance - An Introduction by David Ruppert
solutions manual :: Statistics and Finance - An Introduction by David Ruppert 
solutions manual :: Statistics for Business and Economics 8 ED by Anderson, 
Sweeney
solutions manual :: Statistics for Business and Economics 9 ED by Anderson, 
Sweeney 
solutions manual :: Statistics for Engineering and the Sciences 5th E by 
Mendenhall,Sincich
solutions manual :: Statistics for Engineers and Scientists 2 E by Navidi
solutions manual :: Steel Design, 4th Edition Segui
solutions manual :: STEEL DESIGN, 5th Edition By WILLIAM T. SEGUI
solutions manual :: Stochastic Calculus for Finance, Vol I & Vol II by Yan Zeng
solutions manual :: Stochastic Processes An Introduction by Peter W Jones and 
Peter Smith
solutions manual :: Strength of Materials 4th Ed. by Ferdinand L. Singer & 

Re: Forcing Python to detect DocumentRoot

2013-01-18 Thread Joel Goldstick
On Fri, Jan 18, 2013 at 1:58 PM, Ferrous Cranus wrote:

> Τη Παρασκευή, 18 Ιανουαρίου 2013 3:28:10 μ.μ. UTC+2, ο χρήστης Joel
> Goldstick έγραψε:
>
> > DocumentRoot = os.environ['HOME'] + 'public_html'
>
> Yes, iam using this and it works.
> One last thing:
>
> my python script file is located at
> /home/nikos/public_html/addon_domain/cgi-bin/
>
> How python is able to run the following statement?
>
> f = open( '/home/nikos/public_html/' + page )
>
> which is clearly levels up of addon domain's DocumentRoot?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

My website experience with python has been using mod wsgi (and django), not
cgi.  I can't help you with how to configure cgi, but googling python cgi
might help

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


Re: Vote tallying...

2013-01-18 Thread Kwpolska
On Fri, Jan 18, 2013 at 4:19 PM, Nick Cash
 wrote:
> MySQL would certainly be fine, although I always recommend PostgreSQL over it.
Bonus question, why?
-- 
Kwpolska  | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vote tallying...

2013-01-18 Thread Ben Finney
Kwpolska  writes:

> On Fri, Jan 18, 2013 at 4:19 PM, Nick Cash
>  wrote:
> > MySQL would certainly be fine, although I always recommend
> > PostgreSQL over it.
> Bonus question, why?

The PostgreSQL community gets asked this question so often that they
have a page with resources answering in various ways depending on what
the reader needs to know https://wiki.postgresql.org/wiki/MySQL>.

For me, the reasons are many. Some important ones:

* MySQL happily alters data on input to the database, if it feels the
  need, without regard for data integrity.

  PostgreSQL has always valued the integrity of your data, rejecting
  invalid data before it can become an integrity problem.

* MySQL has atrocious error messages and opaque error reporting, making
  it very difficult to figure out what has actually gone wrong with a
  command it doesn't like.

  PostgreSQL's error reporting is far clearer, helping pinpoint the
  location of the error. It also has an exception-raising mechanism that
  the programmer can use.

* MySQL's development has suffered under Sun, and become virtually
  moribund under Oracle. They operate as a closed shop, occasionally
  tossing GPL-licensed releases over the wall, with very little input
  accepted from the community.

  PostgreSQL development has for a long time now been faster than
  MySQL's, and their community is far more open to contributors and bug
  reports. As a result, the development is much more community-focussed
  and addresses requests more directly.

That latter point is a big flag that Oracle's MySQL is a dead end while
PostgreSQL has a vibrant future. If only from the perspective of who's
going to support you better in the long run, the choice is clear to me.

-- 
 \ “Alternative explanations are always welcome in science, if |
  `\   they are better and explain more. Alternative explanations that |
_o__) explain nothing are not welcome.” —Victor J. Stenger, 2001-11-05 |
Ben Finney

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


Uniquely identifying each & every html template

2013-01-18 Thread Ferrous Cranus
I use this .htaccess file to rewrite every .html request to counter.py

# 
=
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA]
# 
=



counter.py script is created for creating, storing, increasing, displaying a 
counter for each webpage for every website i have.
It's supposed to identify each webpage by a  and then do it's 
database stuff from there

# 
=
# open current html template and get the page ID number
# 
=
f = open( '/home/nikos/public_html/' + page )

# read first line of the file
firstline = f.readline()

# find the ID of the file and store it
pin = re.match( r'', firstline ).group(1)
# 
=

It works as expected and you can see it works normally by viewing: 
http//superhost.gr (bottom down its the counter)

What is the problem you ask?!
Problem is that i have to insert at the very first line of every .html template 
of mine, a unique string containing a number like:

index.html  
somefile.html   
other.html  
nikos.html  
cool.html   

to HELP counter.py identify each webpage at a unique way.

Well its about 1000 .html files inside my DocumentRoot and i cannot edit 
ALL of them of course!
Some of them created by Notepad++, some with the use of Dreamweaver and some 
others with Joomla CMS
Even if i could embed a number to every html page, it would have been a very 
tedious task, and what if a change was in order? Edit them ALL back again? Of 
course not.

My question is HOW am i suppose to identify each and every html webpage i have, 
without the need of editing and embedding a string containing a number for 
them. In other words by not altering their contents.

or perhaps by modifying them a bit. but in an automatic way?

Thank you ALL in advance.


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


Re: Forcing Python to detect DocumentRoot

2013-01-18 Thread Ferrous Cranus
Yes, iam using this and it works. 
One last thing: 

my python script file is located at 
/home/nikos/public_html/addon_domain/cgi-bin/ 

How python is able to run the following statement? 

f = open( '/home/nikos/public_html/' + page ) 

which is clearly levels up of addon domain's DocumentRoot? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vote tallying...

2013-01-18 Thread Tim Chase

On 01/18/13 13:26, Kwpolska wrote:

On Fri, Jan 18, 2013 at 4:19 PM, Nick Cash wrote:

MySQL would certainly be fine, although I always recommend PostgreSQL over it.


Bonus question, why?


I write only from my personal experience, but the following might be 
reasons that Nick recommends PostgreSQL over MySQL:


- Postgres has a history of putting SQL/database integrity first 
where MySQL emphasized speed over correctness.


- it took a long time for MySQL to add more complex transactions and 
complex queries (things got a bit better in the 5.1 iterations of MySQL)


- better support in Postgres for FOREIGN KEY constraints

- a more linear scaling (the performance graphs I've seen for MySQL 
tend to buckle at a certain point, while the PSQL graphs for the 
same load tend to be more linear)


- Postgres has a better track record of scaling across multiple 
processors/cores


- there are just some serious what-the-heck's in MySQL's handling of 
some edge cases regarding NULL values and dates (Feb 31st anybody). 
 There's a good compilation of them at [1].  Any one of them is 
enough to make me queasy at the idea of entrusting my data to it.


- I'm not sure I'd trust MySQL under Oracle these days having seen 
how they (don't) promote it



I do find that administering MySQL is just a bit less headache, but 
at a certain level of administration needs, Postgres offers more 
features.


Just my 0.02 of whatever your local currency is :-)

-tkc


[1]
http://sql-info.de/mysql/gotchas.html





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


Re: Uniquely identifying each & every html template

2013-01-18 Thread John Gordon
In <8deb6f5d-ff10-4b36-bdd6-36f9eed58...@googlegroups.com> Ferrous Cranus 
 writes:

> Problem is that i have to insert at the very first line of every .html 
> template of mine, a unique string containing a number like:

> index.html  
> somefile.html   
> other.html  
> nikos.html  
> cool.html   

> to HELP counter.py identify each webpage at a unique way.

Instead of inserting unique content in every page, can you use the
document path itself as the identifier?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Forcing Python to detect DocumentRoot

2013-01-18 Thread Chris Angelico
On Sat, Jan 19, 2013 at 5:58 AM, Ferrous Cranus  wrote:
> Τη Παρασκευή, 18 Ιανουαρίου 2013 3:28:10 μ.μ. UTC+2, ο χρήστης Joel Goldstick 
> έγραψε:
>
>> DocumentRoot = os.environ['HOME'] + 'public_html'
>
> Yes, iam using this and it works.
> One last thing:
>
> my python script file is located at 
> /home/nikos/public_html/addon_domain/cgi-bin/
>
> How python is able to run the following statement?
>
> f = open( '/home/nikos/public_html/' + page )
>
> which is clearly levels up of addon domain's DocumentRoot?

Time to take a step backward and figure out what you're really trying
to accomplish. I think, after gazing idly into my crystal ball for a
while, that you actually want to chroot your script - instead of
seeing "/home/nikos/public_html/" it would see just "/", and then it
can't access anything outside of that.

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


Re: Vote tallying...

2013-01-18 Thread Andrew Robinson

On 01/18/2013 08:47 AM, Stefan Behnel wrote:

Andrew Robinson, 18.01.2013 00:59:

I have a problem which may fit in a mysql database

Everything fits in a MySQL database - not a reason to use it, though. Py2.5
and later ship with sqlite3 and if you go for an external database, why use
MySQL if you can have PostgreSQL for the same price?
MySQL is provided by the present server host.  It's pretty standard at 
web hosting sites.
It works through "import MySQLdb" -- and it means an IP call for every 
action...

Postgre isn't available :( otherwise, I'd use it

I'm mildly concerned about scaling issues but don't have a lot of 
time (just a few days) to come to a decision.  I don't need high 
performance, just no grotesque degradation when the system is scaled up, 
and no maintenance nightmare.  The votes table is going to get 
monsterous if all votes are held in one table


Your comment about sqlite is interesting; I've never used it before.
At a glance, it uses individual files as databases, which is good... But it 
wants to lock the entire database against reads as well as writes when any 
access of the database happens.  Which is bad...

http://www.sqlite.org/different.html
http://www.sqlite.org/whentouse.html


... XML files are a rather static thing and meant to be
processed from start to end on each run. That adds up if the changes are
small and local while the file is ever growing. You seem to propose one
file per article, which might work. That's unlikely to become too huge to
process, and Python's cElementTree is a very fast XML processor.

Yes, that's exactly what I was thinking one file/article.

It's attractive, I think, because many Python programs are allowed to 
read the XML file concurrently, but only one periodically updates it as 
a batch/chron/or triggered process; eg: the number/frequency of update 
is actually controllable.


eg: MySQL accumulates a list of new votes and vote changes and python 
occasionally flushes the database into the archive file. That way, MySQL 
only maintains a small database of real-time changes, and the 
speed/accuracy of the vote tally can be tailored to the user's need.


However, your problem sounds a lot like you could map it to one of the dbm
databases that Python ships. They work like dicts, just on disk.
Doing a Google search, I see some of these that you are mentioning -- 
yes, they may have some potential.


IIUC, you want to keep track of comments and their associated votes, maybe
also keep a top-N list of the highest voted comments. So, keep each comment
and its votes in a dbm record, referenced by the comment's ID (which, I
assume, you keep a list of in the article that it comments on).
The comments themselves are just ancillary information; the votes only 
apply to the article itself at this time.  The two pieces of feedback 
information are independent, occasionally having a user that gives both 
kinds.  Statistically, there are many votes -- and few comments.


Each archive file has the same filename as the article that is being 
commented or voted on; but with a different extension (eg: xml, or 
.db,or...) so there's no need to store article information  on each vote 
or comment; (unlike the MySQL database, which has to store all that 
information for every vote ugh!)



  You can use
pickle (see the shelve module) or JSON or whatever you like for storing
that record. Then, on each votes update, look up the comment, change its
votes and store it back. If you keep a top-N list for an article, update it
at the same time. Consider storing it either as part of the article or in
another record referenced by the article, depending of how you normally
access it. You can also store the votes independent of the comment (i.e. in
a separate record for each comment), in case you don't normally care about
the votes but read the comments frequently. It's just a matter of adding an
indirection for things that you use less frequently and/or that you use in
more than one place (not in your case, where comments and votes are unique
to an article).

You see, lots of options, even just using the stdlib...

Stefan


Yes, lots of options
Let's see... you've noticed just about everything important, and have 
lots of helpful thoughts; thank you.


There are implementation details I'm not aware of regarding how the 
file-system dictionaries (dbm) work; and I wouldn't know how to compare 
it to XML access speed either but I do know some general information 
about how the data might be handled algorithmically; and which might 
suggest a better Python import to use?


If I were to sort all votes by voter ID (a 32 bit number), and append 
the vote value (A 4 to 8bit number);  Then a vote becomes a chunk of 40 
bits, fixed length; and I can stack one right after another in a compact 
format.


Blocks of compacted votes are ideal for binary searching; since they 
have fixed length... and if I am only wanting to change a vote, I don't 
need to re-w

Re: Vote tallying...

2013-01-18 Thread Chris Angelico
On Sat, Jan 19, 2013 at 7:24 AM, Ben Finney  wrote:
> * MySQL's development has suffered under Sun, and become virtually
>   moribund under Oracle. They operate as a closed shop, occasionally
>   tossing GPL-licensed releases over the wall, with very little input
>   accepted from the community.

I don't know whether it's a legit concern or pure FUD, but it's been
suggested that since the MySQL license is GPL and not LGPL, any code
that links against it is forced to be GPL too. I'm not sure how far
that goes (eg if you're using it from Python, at what point does it
stop being "code linked to GPL code" and start being a discrete
system), and IANAL, but I prefer to work with systems with more
freedom in their licensing. PostgreSQL is under a BSD-like license, so
it can be used without issues.

Also, and a completely irrelevant point but maybe of curiosity: It's
perfectly possible to use PostgreSQL without linking against libpq (by
reimplementing the wire protocol - Pike's pgsql module does that), but
I've never heard of anyone doing that with MySQL. Perhaps if someone
cared, they could release a non-GPL equivalent to libmysql and that
would solve this problem. Not gonna be me, though, I'm quite happy
with PG 9.1.

MySQL works very nicely with PHP. They each have certain sloppinesses
that work well together to make it easy for an idiot to create a
dynamic web site. PostgreSQL works equally nicely with stricter
languages, where if you make a mistake, you get an error. MySQL gives
your script a place to store data; PostgreSQL lets you set up a
database and have application(s) manipulate it. The assumption in
MySQL is that the script is always right; the assumption in PostgreSQL
is that the database is always right. It's a philosophical
distinction, and you just have to take your choice. For me, that's an
easy choice, partly since I grew up with IBM DB2 on OS/2, with
extremely strict rules (and, by the way, nothing *like* the
performance of a modern database - old 200MB IDE hard drives didn't
give quite the same TPS as a modern SATA).

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


Re: Uniquely identifying each & every html template

2013-01-18 Thread Dave Angel

On 01/18/2013 03:48 PM, Ferrous Cranus wrote:

I use this .htaccess file to rewrite every .html request to counter.py

# 
=
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^/?(.+\.html) /cgi-bin/counter.py?htmlpage=$1 [L,PT,QSA]
# 
=



counter.py script is created for creating, storing, increasing, displaying a 
counter for each webpage for every website i have.
It's supposed to identify each webpage by a  and then do it's 
database stuff from there

# 
=
# open current html template and get the page ID number
# 
=
f = open( '/home/nikos/public_html/' + page )

# read first line of the file
firstline = f.readline()

# find the ID of the file and store it
pin = re.match( r'', firstline ).group(1)
# 
=

It works as expected and you can see it works normally by viewing: 
http//superhost.gr (bottom down its the counter)

What is the problem you ask?!
Problem is that i have to insert at the very first line of every .html template 
of mine, a unique string containing a number like:

index.html  
somefile.html   
other.html  
nikos.html  
cool.html   

to HELP counter.py identify each webpage at a unique way.

Well its about 1000 .html files inside my DocumentRoot and i cannot edit 
ALL of them of course!
Some of them created by Notepad++, some with the use of Dreamweaver and some 
others with Joomla CMS
Even if i could embed a number to every html page, it would have been a very 
tedious task, and what if a change was in order? Edit them ALL back again? Of 
course not.

My question is HOW am i suppose to identify each and every html webpage i have, 
without the need of editing and embedding a string containing a number for 
them. In other words by not altering their contents.

or perhaps by modifying them a bit. but in an automatic way?

Thank you ALL in advance.




I don't understand the problem.  A trivial Python script could scan 
through all the files in the directory, checking which ones are missing 
the identifier, and rewriting the file with the identifier added.


So, since you didn't come to that conclusion, there must be some other 
reason you don't want to edit the files.  Is it that the real sources 
are elsewhere (e.g. Dreamweaver), and whenever one recompiles those 
sources, these files get replaced (without identifiers)?


If that's the case, then I figure you have about 3 choices:

1) use the file path as your key, instead of requiring a number
2) use a hash of the page  (eg. md5) as your key.  of course this could 
mean that you get a new value whenever the page is updated.  That's good 
in many situations, but you don't give enough information to know if 
that's desirable for you or not.
3) Keep an external list of filenames, and their associated id numbers. 
 The database would be a good place to store such a list, in a separate 
table.


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


Re: Uniquely identifying each & every html template

2013-01-18 Thread Ferrous Cranus
Τη Παρασκευή, 18 Ιανουαρίου 2013 10:59:17 μ.μ. UTC+2, ο χρήστης John Gordon 
έγραψε:

> Instead of inserting unique content in every page, can't you use the 
> document path itself as the identifier?

No, i cannot, becaue it would mess things at later time when i for example:

1. mv name.html othername.html   (document's filename altered)
2. mv name.html /subfolder/name.html   (document's path altered)

Hence, new database counters will be created for each of the above cases.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vote tallying...

2013-01-18 Thread Zero Piraeus
:

On 18 January 2013 16:57, Tim Chase  wrote:
>
> - there are just some serious what-the-heck's in MySQL's handling of some
> edge cases regarding NULL values and dates (Feb 31st anybody).  There's a
> good compilation of them at [1].
>
> [1]
> http://sql-info.de/mysql/gotchas.html

I'm getting the following from that URL:

ERROR: database not available

... which, as irony goes, is kinda delicious :-)

 -[]z.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyWart: Exception error paths far too verbose

2013-01-18 Thread Rick Johnson
On Wednesday, January 16, 2013 6:51:31 PM UTC-6, Terry Reedy wrote:
> I missed in your original post that you only want one consistent 
> personal library path abbreviated, leaving everything else alone. So the 
> above is not applicable. And a custom excepthook very easy.
> 
> How should the traceback mechanism -will- know what that path is?

Well, the jury is still deliberating on the specifics, however, as for myself, 
i would sway more to the /explicit/ side. 

A few possibilities include:

 * A configuration file. Python already checks the current
   directory for ".pth" files, which it then reads and adds
   the contained paths to sys.path --  most folks stopped
   typing commands OVER and OVER on the commandline many
   years ago. But to each his own.
 
 * A runtime command or keyword placed in a script (YUCK!)
 
 * A commandline switch (only good for members of the
   python historical society.) 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vote tallying...

2013-01-18 Thread Kushal Kumaran
Chris Angelico  writes:

> On Sat, Jan 19, 2013 at 7:24 AM, Ben Finney  
> wrote:
>> * MySQL's development has suffered under Sun, and become virtually
>>   moribund under Oracle. They operate as a closed shop, occasionally
>>   tossing GPL-licensed releases over the wall, with very little input
>>   accepted from the community.
>
> I don't know whether it's a legit concern or pure FUD, but it's been
> suggested that since the MySQL license is GPL and not LGPL, any code
> that links against it is forced to be GPL too. I'm not sure how far
> that goes (eg if you're using it from Python, at what point does it
> stop being "code linked to GPL code" and start being a discrete
> system), and IANAL, but I prefer to work with systems with more
> freedom in their licensing. PostgreSQL is under a BSD-like license, so
> it can be used without issues.
>

Oracle have a page about this:
http://www.mysql.com/about/legal/licensing/foss-exception/

> Also, and a completely irrelevant point but maybe of curiosity: It's
> perfectly possible to use PostgreSQL without linking against libpq (by
> reimplementing the wire protocol - Pike's pgsql module does that), but
> I've never heard of anyone doing that with MySQL. Perhaps if someone
> cared, they could release a non-GPL equivalent to libmysql and that
> would solve this problem. Not gonna be me, though, I'm quite happy
> with PG 9.1.
>

As far as python goes, there are at least two pure-python
implementations of the mysql protocol available:

- https://github.com/petehunt/PyMySQL (MIT license)

- https://launchpad.net/myconnpy (GPL)

The second one is an "official" Oracle project.  Both of them support
python 3 as well.

> MySQL works very nicely with PHP. They each have certain sloppinesses
> that work well together to make it easy for an idiot to create a
> dynamic web site. PostgreSQL works equally nicely with stricter
> languages, where if you make a mistake, you get an error. MySQL gives
> your script a place to store data; PostgreSQL lets you set up a
> database and have application(s) manipulate it. The assumption in
> MySQL is that the script is always right; the assumption in PostgreSQL
> is that the database is always right. It's a philosophical
> distinction, and you just have to take your choice. For me, that's an
> easy choice, partly since I grew up with IBM DB2 on OS/2, with
> extremely strict rules (and, by the way, nothing *like* the
> performance of a modern database - old 200MB IDE hard drives didn't
> give quite the same TPS as a modern SATA).
>

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner Tutorials

2013-01-18 Thread Rick Johnson
On Friday, January 18, 2013 11:04:39 AM UTC-6, Rik wrote:
> The reason for disabling right-click has nothing to do
> with protecting content, and everything to do with
> stopping my students from taking the lazy way out.
> 
> Given the chance, they'll copy/paste the code and download
> the designs and edit them slightly. They'd get through the
> tutorials in about 25 minutes and have learnt next to
> nothing.
>
> In talking to students about existing resources, they said
> that blindly copying code didn't really help them get a
> deep understanding of algorithms and how to apply them to
> other problems.

Well anyone who is just blindly copying code to get through a CS course is 
obviously not a "natural" problem solver ,and thus, /incapable/ of becoming a 
proficient programmer anyhow. Programming *IS* problem solving. If you don't 
get any thrill from the hunt, you might as well go home and watch Monty python 
until your eyes bleed or the next welfare check arrives.

But don't paint with too wide a brush on the copy-paste subject matter either 
because i have /no/ hesitation to copy paste when the code is mostly 
boilerplate required by some asinine interface, like oh I dunno, WINDOWS GUI 
PROGRAMMING!!! ಠ_ಠ. I am not about to invest one second /learning/ much less 
trying to /comprehend/ why someone would create and release such a gawd awful 
monstrosity.

Natural problem solvers always love a challenge and they always like to peek 
under the hood and see what makes this or that "tick". You need no more than to 
present these people with a problem and they *WILL* discover the answer (given 
enough time of course). 

  "The only limit to an individuals imagination is his lifespan" --rr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reinforced Concrete: Mechanics and Design (5th Ed., James G. MacGregor & James K. Wight)

2013-01-18 Thread Roy Smith
Can whoever manages the mailing list block this bozo?

In article ,
 kalvinmanual1  wrote:

> I have solutions manuals to all problems and exercises in these textbooks. To 
> get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com 
> and let me know its title, author and edition. Please this service is NOT 
> free.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any built-in ishashable method ?

2013-01-18 Thread Kushal Kumaran
Peter Otten <__pete...@web.de> writes:

> Jean-Michel Pichavant wrote:
>
>> That brings me to another question, is there any valid test case where
>> key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design
>> flaw ?
>
> I don't think there is a use case for such a behaviour other than annoying 
> your collegues ;)
>

It's fairly common.  The set of possible keys can be much larger
(possibly infinite) than the set of possible hash values (restricted to
32-bit or 64-bit integer values, afaict).

-- 
regards,
kushal

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


Re: Vote tallying...

2013-01-18 Thread Chris Angelico
On Sat, Jan 19, 2013 at 12:25 PM, Kushal Kumaran
 wrote:
> Chris Angelico  writes:
>
>> On Sat, Jan 19, 2013 at 7:24 AM, Ben Finney  
>> wrote:
>>> * MySQL's development has suffered under Sun, and become virtually
>>>   moribund under Oracle. They operate as a closed shop, occasionally
>>>   tossing GPL-licensed releases over the wall, with very little input
>>>   accepted from the community.
>>
>> I don't know whether it's a legit concern or pure FUD, but it's been
>> suggested that since the MySQL license is GPL and not LGPL, any code
>> that links against it is forced to be GPL too. I'm not sure how far
>> that goes (eg if you're using it from Python, at what point does it
>> stop being "code linked to GPL code" and start being a discrete
>> system), and IANAL, but I prefer to work with systems with more
>> freedom in their licensing. PostgreSQL is under a BSD-like license, so
>> it can be used without issues.
>>
>
> Oracle have a page about this:
> http://www.mysql.com/about/legal/licensing/foss-exception/

Thanks, I was working from memory and wasn't sure. So yes, it's a
fully legit issue, and it basically means you can't use MySQL with any
proprietary code.

So if I create a thin wrapper around libmysql, release that wrapper
under the BSD 2-clause license (which is listed among the valid
licenses - at least, I'm guessing that they mean the 2-clause), and
then use that wrapper in a proprietary project, is that valid? This is
getting ridiculously messy, and I'm definitely glad now not using
MySQL at work.

> As far as python goes, there are at least two pure-python
> implementations of the mysql protocol available:
>
> - https://github.com/petehunt/PyMySQL (MIT license)

That should be perfectly legal then. You're not linking against any
GPL'd code, you're just connecting via a TCP socket to a GPL
application. Really, I don't see what GPLing the client library
achieves, other than creating a mess for people.

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


Re: Safely add a key to a dict only if it does not already exist?

2013-01-18 Thread Chris Rebert
On Friday, January 18, 2013, Steven D'Aprano wrote:

> I wish to add a key to a dict only if it doesn't already exist, but do it
> in a thread-safe manner.
>
> The naive code is:
>
> if key not in dict:
> dict[key] = value
>
>
> but of course there is a race condition there: it is possible that

another thread may have added the same key between the check and the
> store.
>
> How can I add a key in a thread-safe manner?
>

I'm not entirely sure, but have you investigated dict.setdefault() ?


-- 
Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner Tutorials

2013-01-18 Thread Evan Driscoll
On 1/18/2013 7:25 PM, Rick Johnson wrote:
> Well anyone who is just blindly copying code to get through a CS
> course is obviously not a "natural" problem solver ,and thus,
> /incapable/ of becoming a proficient programmer anyhow. Programming
> *IS* problem solving. If you don't get any thrill from the hunt,
> you might as well go home and watch Monty python until your eyes
> bleed or the next welfare check arrives.

I have only skimmed this thread and so am unsure exactly what is being
protected against casual copy/paste, but at least on its face I would
*vehemently* disagree with your statement.

There are at least two significant problems with it. First you ignore
short-term pressures. It sounds like the tutorial in question is being
used in some kind of course? If so, perhaps an assignment or two are
badly timed with other life events (projects from other classes,
external pressures, etc.) and, even though a person WOULD enjoy and be
competent at solving the problem, those constraints pressure them to
take the short-term "out" in the programming course, which also leads to
them learning so much.

But the bigger problem is that -- while you are right that programming
is problem solving -- doing problem solving is probably not why most
people got into it. At least personally, I got into it because I liked
making stuff. If someone is attracted to the field because they go "oh
hey I can program the next video game!" that doesn't automatically mean
that they won't be good at it, but it may be that the problem-solving
aspect of it is an acquired taste.

As an analogy, I've been rock climbing for several years. There are
several types of climbing; two of them are top roping, which is roped
climbing and what you see most people in a climbing gym doing, and
bouldering, which is climbing routes low to the ground (usually under 3
meters or so) without a rope. When I started, I basically exclusively
did top roping. Bouldering seemed... dumb to me, like it was missing the
point: "the reason you go climbing is to *climb*, and bouldering gives
you very little of that." :-) But after I was going for a while, getting
high above the ground became less of why I did it and the challenge of
figuring out the right movements and such to complete the route started
being my primary motivation for liking it. And those are things that
bouldering has in fine measures; in some respects, it does that *better*
than roped climbing*.

(* Arguing about roped climbing vs bouldering might be that community's
version of "Emacs is better than Vi". :-))

In other words, why I started climbing is very different from why I
continued it. And I feel that the same could be said of programming.
Just because you don't enjoy parts of programming when you're starting
out doesn't mean that you're a lost cause by ANY means.

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


Question related to multiprocessing.Process

2013-01-18 Thread Cen Wang
Hi, when I use multiprocessing.Process in this way:

from multiprocessing import Process

class MyProcess(Process):

def __init__(self):
Process.__init__(self)

def run(self):
print 'x'

p = MyProcess()
p.start()

It just keeps printing 'x' on my command prompt and does not end. But I think 
MyProcess should print an 'x' and then terminate. I don't why this is 
happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Safely add a key to a dict only if it does not already exist?

2013-01-18 Thread Lie Ryan

On 19/01/13 15:15, Chris Rebert wrote:

On Friday, January 18, 2013, Steven D'Aprano wrote:

I wish to add a key to a dict only if it doesn't already exist, but
do it
in a thread-safe manner.

The naive code is:

if key not in dict:
 dict[key] = value


but of course there is a race condition there: it is possible that

another thread may have added the same key between the check and the
store.

How can I add a key in a thread-safe manner?


I'm not entirely sure, but have you investigated dict.setdefault() ?


dict.setdefault() was not atomic on older python version, they were made 
atomic in Python 2.7.3 and Python 3.2.3.


See bug13521 in the issue tracker http://bugs.python.org/issue13521

PS: The bug tracker seems down at the moment, so pulled this from 
Google's cache:

https://webcache.googleusercontent.com/search?q=cache:59PO_F-VEfwJ:bugs.python.org/issue13521+&cd=1&hl=en&ct=clnk&client=ubuntu

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


Re: Question related to multiprocessing.Process

2013-01-18 Thread Chris Angelico
On Sat, Jan 19, 2013 at 3:50 PM, Cen Wang  wrote:
> Hi, when I use multiprocessing.Process in this way:
>
> from multiprocessing import Process
>
> class MyProcess(Process):
>
> def __init__(self):
> Process.__init__(self)
>
> def run(self):
> print 'x'
>
> p = MyProcess()
> p.start()
>
> It just keeps printing 'x' on my command prompt and does not end. But I think 
> MyProcess should print an 'x' and then terminate. I don't why this is 
> happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance.

Multiprocessing on Windows requires that your module be importable. So
it imports your main module, which instantiates another MyProcess,
starts it, rinse and repeat. You'll need to protect your main routine
code:

if __name__=="__main__":
p = MyProcess()
p.start()

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


Re: Question related to multiprocessing.Process

2013-01-18 Thread Cen Wang
Thanks! It now works!
On Saturday, 19 January 2013 13:05:07 UTC+8, Chris Angelico  wrote:
> On Sat, Jan 19, 2013 at 3:50 PM, Cen Wang  wrote:
> 
> > Hi, when I use multiprocessing.Process in this way:
> 
> >
> 
> > from multiprocessing import Process
> 
> >
> 
> > class MyProcess(Process):
> 
> >
> 
> > def __init__(self):
> 
> > Process.__init__(self)
> 
> >
> 
> > def run(self):
> 
> > print 'x'
> 
> >
> 
> > p = MyProcess()
> 
> > p.start()
> 
> >
> 
> > It just keeps printing 'x' on my command prompt and does not end. But I 
> > think MyProcess should print an 'x' and then terminate. I don't why this is 
> > happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance.
> 
> 
> 
> Multiprocessing on Windows requires that your module be importable. So
> 
> it imports your main module, which instantiates another MyProcess,
> 
> starts it, rinse and repeat. You'll need to protect your main routine
> 
> code:
> 
> 
> 
> if __name__=="__main__":
> 
> p = MyProcess()
> 
> p.start()
> 
> 
> 
> ChrisA

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


Re: problems trying to build python 2.6 as a shared library

2013-01-18 Thread scubbojj
On Friday, 25 September 2009 04:36:28 UTC-7, Marco Nawijn  wrote:
> On Sep 25, 1:08 pm, Chris Withers  wrote:
> > Hi All,
> >
> > I'm trying to build Python 2.6 as a shared library, so I did:
> >
> >    ./configure --enable-shared
> >    make
> >    make altinstall
> >
> > No obvious signs of failure, but when I try and use the resulting
> > python, I get:
> >
> > python2.6: error while loading shared libraries: libpython2.6.so.1.0:
> > cannot open shared object file: No such file or directory
> >
> > Why might that be?
> >
> > cheers,
> >
> > Chris
> >
> > --
> > Simplistix - Content Management, Batch Processing & Python Consulting
> >             -http://www.simplistix.co.uk
> 
> Hello Chris,
> 
> The dynamic loader cannot find the python shared library.  There are
> at least 2 options:
> 1. Add path that contains the shared library to the
> LD_LIBRARY_PATH environment variable. In a bash shell this can be
> accomplished by:  export LD_LIBRARY_PATH=/path/to/python_shared_lib:
> $LD_LIBRARY_PATH
> 2. Add path to dynamic linker configuration file. This typically
> is in '/etc/ld.so.conf'. See man page for ld for more information.
> 
> Note that I assumed that you are on a Unix/Linux machine.
> 
> Regards,
> 
> Marco

Could you elaborate on this for a Linux newbie please? I carried out step 1 
with no problems, but when I view /etc/ld.so.conf, I get the following:

$ cat /etc/ld.so.conf
include ld.so.conf.d/*.conf

I don't know how to use ld - I see from the man pag that it's used for linking 
files, but I don't know (in this context) what files I want to be linking to 
what.

I've copied libpython2.7.so and libpython2.7.so.1.0 to the folder in 
$LD_LIBRARY_PATH, meaning I don't get the problems detailed in the original 
post anymore, but I'm concerned that I'm sticking a plaster over a bigger 
problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reinforced Concrete: Mechanics and Design (5th Ed., James G. MacGregor & James K. Wight)

2013-01-18 Thread Robert Miles

On 1/18/2013 7:32 PM, Roy Smith wrote:

Can whoever manages the mailing list block this bozo?

In article ,
  kalvinmanual1  wrote:


I have solutions manuals to all problems and exercises in these textbooks. To
get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com
and let me know its title, author and edition. Please this service is NOT
free.


I don't use the mailing list, but I'll try another method
for blocking this alleged human.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Beginner Tutorials

2013-01-18 Thread Rick Johnson
On Friday, January 18, 2013 10:36:09 PM UTC-6, Evan Driscoll wrote:
> I have only skimmed this thread and so am unsure exactly what is being
> protected against casual copy/paste, but at least on its face I would
> *vehemently* disagree with your statement.

Well if you skim just a wee bit more you will see how i took a view from both 
sides of the argument :)

> There are at least two significant problems with it. First you ignore
> short-term pressures. 

I think we can all understand short term pressures (especially those among us 
who actually work for a living) however, cheating not only harms the cheater, 
but also degrades the value of the education that the fellow students worked 
honestly to achieve -- that's my real beef.

> But the bigger problem is that -- while you are right that programming
> is problem solving -- doing problem solving is probably not why most
> people got into it. At least personally, I got into it because I liked
> making stuff. 

Is not "making stuff" a form of problem solving? You may not enjoy writing code 
because it solves a real world tangible problem (like a calculator for solving 
math equations or a spreadsheet for organizing data, or flight control 
software... wait, don't use python for the last one!) but the "act" of creating 
anything involves solving problems, yes? 

 * What am i making?
 * What language provides the tools i need?
 * How will it interface with the world?
 * What will it do? (Even if only to not throw an exception) :)
 * Will it be automated or require input control?
 * GUI or command line?
 * What dependencies will it require?
 * etc...
 
And that's just the initial draft design phase. These handful of problems have 
deeply nested sub-problems hidden below.

But maybe you are referring to the satisfaction you get when witnessing your 
"creation" in action. Ah, yes. This is a great feeling! Especially when you've 
worked for hours tracking some subtle bug because of a bad language feature or 
poor interface and you almost threw in the towel twenty times, but /something/ 
kept you coming back. What was it? Was it the fact that you would not allow 
yourself to be defeated? Was it the addiction to the satisfaction you get from 
creating a program that runs without error and actually does something useful? 
These are the monkeys on the back of every good programmer. 

> If someone is attracted to the field because they go "oh
> hey I can program the next video game!" that doesn't automatically mean
> that they won't be good at it, but it may be that the problem-solving
> aspect of it is an acquired taste.

Like these people you mention, my initial interest was very specific. I needed 
to create a few tools for myself, and i thought that would be the extent of my 
programming. But after writing a few apps i was hooked! And as i progressed 
writing more and more code, i became more and more addicted. Coding actually 
transformed the way i interpret the world. I am constantly looking for 
consistency, logic, intuitiveness in every interface around me. That could be 
my car, my toaster, whatever. But most importantly, programming has honed my 
problem solving skills to razor perfection! Especially OOP. Which can be 
transformed into many problem domains.

I think a lot of energetic and naive people get attracted to writing code from 
games, however, once they start up the steep learning curve without an ability 
to problem-solve (or a good starter language like python), they get frustrated 
and quit. These people cannot problem-solve themselves out of a wet paper bag! 

And i think a good programmer, along with being a great problem solver, is a 
bit of a risk taker. I mean, how else are you going to learn without taking 
risks. An infinite recursion here, a segfault there... accidentally used rmdir 
on your porn folder, oops! It's all part of cutting teeth.

Another trait of the programmer, an innate sense of curiosity. A good litmus 
test is to offer a complicated software application to a group of people of 
which none have used before and all are unfamiliar with. 

Then, see who becomes proficient with the interface. That's the subgroup who 
will make great programmers! While the dummies start out reading the manual, 
the natural problem solvers will jump head first into the interface and attempt 
to intuit every command. 

When, after exhausting all there comprehensive abilities, they don't understand 
a certain feature, then and *only* then do they consult the docs. And 
sometimes, the doc are just insufficient anyways. 

But the point is, the true problem solver discovers his own weaknesses, takes 
mental note of them, and then methodically *DESTROYS* them. Divide and conquer. 

This is the method by which intelligent beings solve problems.

> As an analogy, I've been rock climbing for several years. There are
> several types of climbing; two of them are top roping, which is roped
> climbing and what you see most people in a climbing gym doing, 

Re: Vote tallying...

2013-01-18 Thread Stefan Behnel
Chris Angelico, 19.01.2013 03:00:
> On Sat, Jan 19, 2013 at 12:25 PM, Kushal Kumaran wrote:
>> Chris Angelico writes:
>>
>>> On Sat, Jan 19, 2013 at 7:24 AM, Ben Finney wrote:
 * MySQL's development has suffered under Sun, and become virtually
   moribund under Oracle. They operate as a closed shop, occasionally
   tossing GPL-licensed releases over the wall, with very little input
   accepted from the community.
>>>
>>> I don't know whether it's a legit concern or pure FUD, but it's been
>>> suggested that since the MySQL license is GPL and not LGPL, any code
>>> that links against it is forced to be GPL too. I'm not sure how far
>>> that goes (eg if you're using it from Python, at what point does it
>>> stop being "code linked to GPL code" and start being a discrete
>>> system), and IANAL, but I prefer to work with systems with more
>>> freedom in their licensing. PostgreSQL is under a BSD-like license, so
>>> it can be used without issues.
>>
>> Oracle have a page about this:
>> http://www.mysql.com/about/legal/licensing/foss-exception/
> 
> Thanks, I was working from memory and wasn't sure. So yes, it's a
> fully legit issue, and it basically means you can't use MySQL with any
> proprietary code.

Well, you can, just like with any proprietary software that you link
against GPL code. As long as you don't ship your code to someone else who
doesn't have access to your source code, you're free to do whatever you
like with it. That's usually the case when you deploy your software on your
own servers, for example. Only if you distribute your software to other
people, the GPL enforces that you give them your source code under the same
license.

Stefan


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


Re: Safely add a key to a dict only if it does not already exist?

2013-01-18 Thread Vito De Tullio
Steven D'Aprano wrote:

> I wish to add a key to a dict only if it doesn't already exist, but do it
> in a thread-safe manner.
> 
> The naive code is:
> 
> if key not in dict:
> dict[key] = value
> 
> 
> but of course there is a race condition there: it is possible that
> another thread may have added the same key between the check and the
> store.
> 
> How can I add a key in a thread-safe manner?

using locks?

import threading

 

lock = threading.Lock()
with lock:
if key not in dict:
dict[key] = value


-- 
ZeD

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


Re: Safely add a key to a dict only if it does not already exist?

2013-01-18 Thread Vito De Tullio
Chris Rebert wrote:

>> How can I add a key in a thread-safe manner?
> I'm not entirely sure, but have you investigated dict.setdefault() ?

but how setdefault makes sense in this context? It's used to set a default 
value when you try to retrieve an element from the dict, not when you try to 
set a new one ...

-- 
ZeD

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


Re: Safely add a key to a dict only if it does not already exist?

2013-01-18 Thread Mitya Sirenef

On 01/19/2013 02:27 AM, Vito De Tullio wrote:

Chris Rebert wrote:


How can I add a key in a thread-safe manner?

I'm not entirely sure, but have you investigated dict.setdefault() ?

but how setdefault makes sense in this context? It's used to set a default
value when you try to retrieve an element from the dict, not when you try to
set a new one ...



I guess setdefault with a sentinel default value, then set to your
new value if d[k] is sentinel?

 - mitya


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

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


Sending a broadcast message using raw sockets

2013-01-18 Thread Peter Steele
I want to write a program in Python that sends a broadcast message using raw 
sockets. The system where this program will run has no IP or default route 
defined, hence the reason I need to use a broadcast message.

I've done some searches and found some bits and pieces about using raw sockets 
in Python, but I haven't been able to find an example that explains how to 
construct a broadcast message using raw sockets.

Any pointers would be appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any built-in ishashable method ?

2013-01-18 Thread Peter Otten
Kushal Kumaran wrote:

> Peter Otten <__pete...@web.de> writes:
> 
>> Jean-Michel Pichavant wrote:
>>
>>> That brings me to another question, is there any valid test case where
>>> key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design
>>> flaw ?
>>
>> I don't think there is a use case for such a behaviour other than
>> annoying your collegues ;)
>>
> 
> It's fairly common.  The set of possible keys can be much larger
> (possibly infinite) than the set of possible hash values (restricted to
> 32-bit or 64-bit integer values, afaict).

Sorry, I misread the quoted text. If you replace

key1 != key2 and hash(key1) == hash(key2)

in Jean-Michel's question with

key1 == key2 and hash(key1) != hash(key2)

my reply should start to make sense...

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