Re: Select fails when cookie tried to get a numeric value

2013-10-05 Thread Denis McMahon
On Sat, 05 Oct 2013 16:38:14 +0300, Νίκος Αλεξόπουλος wrote:

 [my cookie code is fucked]

Hi Nick

I had never used python for www before yesterday. I had never used python 
before about 6 months ago.

In the last 24 hours I have installed mod-wsgi on my apache web server, 
and written test code that enables me to see the result of all 
environment data, parse the get string, parse post data, set and parse 
cookies, and save session data to a file specific to the cookie data.

There may be better ways to do some of it, but it works.

Here is a link to the text of my python file:

http://www.sined.co.uk/tmp/index.py.txt

Once you have read through it (there are comments) and understood how it 
handles cookies and session data, you will realise that you can add and 
modify any session data just by adding relevant items to and reading them 
from the session data dictionary. The session data stays on the server, 
the cookie simply identifies the session (and the session data file), and 
hopefully is unique to the user.

Don't ask me any questions about why I did something the way I did it. I 
did it that way because it works. If anyone knows a different way that 
also works and maybe works better, feel free to discuss it. But Nick, 
don't you dare suggest any change that doesn't work because you think it 
looks better.

If you don't understand a module function that I've used, read the python 
documentation for it.

If you think you have a question that is  not covered by the above 
statements, feel free to ask me, here, why I wrote a given line number or 
group of line numbers the way I did. However, see the notes above - the 
answer will probably be because it works that way.

If you quote the whole file or even large chunks of it here, I am 
finished with trying to help you, ever!

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


Re: I haev fixed it

2013-10-02 Thread Denis McMahon
On Wed, 02 Oct 2013 15:01:31 +0100, Mark Lawrence wrote:

 I want a full apology to this entire group now for your behaviour, and a
 very specific formal apology to myself for your completely unfounded
 allegations.  I expect to see this by 23:59 2nd October 2013 BST.

Honestly? Or you'll do what? Sulk? Cry like a baby? Whinge and whine 
loudly? Or are you going to throw money away on this? Because if you are, 
I have a bridge for sale.

He's an idiot. Everyone can see he's an idiot. I don't think anyone here 
believes that he has any ability at all in identifying who used what 
method to upload a file to his server.

If you want to make yourself appear to be as stupid as he makes himself 
appear all the time, carry on making demands. Because when push comes to 
shove, the only satisfaction you'll ever get is by taking civil action 
against him, and that's going to mean you putting your money up front, 
and hoping you can recover those costs from him afterwards. If he hasn't 
got the money, your costs judgement against him is just a piece of 
worthless paper, but your legal costs in bringing the action are your 
responsibility.

So before starting down the path of threatening legal action, I suggest 
you run a comprehensive credit check on your target.

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


Re: JUST GOT HACKED

2013-10-02 Thread Denis McMahon
On Wed, 02 Oct 2013 13:22:25 +0300, Νίκος wrote:

 I was even mocked because all i wanted to do was to optimize code and
 use the best solution there is to it.

No. You were mocked because you insisted that your broken one line code 
was a better looking solution than anyone elses working multi line 
solution. The mocking was because you were failing to recognise that if 
it doesn't work, it's not a solution, no matter how nice it looks.

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


Re: Can arbitrary code run in a server if someone's know just the MySQL password?

2013-10-02 Thread Denis McMahon
On Wed, 02 Oct 2013 17:46:08 +0300, Νίκος wrote:

 But i need to know what happened and how this .html file got uploaded.

The html file started out in an editor on on another machine, and was 
created by someone typing at the keyboard. It was then saved to hard disk 
as a file. The other machine then read the file into memory, and then 
sent it as a byte stream to the tcp/ip stack, where it was broken down 
down into packets which travelled across the tcp/ip network onto your 
server. Your server then re-assembled the packets into a byte stream 
which filled a block of memory, and then wrote the contents of that block 
of memory to disc as a file.

(This explanation may contain some assumptions.)

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


Re: I haev fixed it

2013-10-02 Thread Denis McMahon
On Wed, 02 Oct 2013 17:07:43 +0100, Mark Lawrence wrote:

 Pardon my ignorance but how does asking for an apology translate into
 threatening legal action, something that I've already stated that I
 won't do for several reasons, the main one of which is that I find these
 threads hilarious?

You're making the sort of demand for an apology that's usually followed 
by a comment such as or I will sue you for defamation.

Personally I think demanding an apology is a waste of time and ng 
bandwidth, but *shrugs* whatever.

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


Re: Help with python functions?

2013-10-01 Thread Denis McMahon
On Tue, 01 Oct 2013 10:53:26 -0700, kjakupak wrote:

 I ended up with these. I know they're only like half right...
 I was wondering if any of you had to do this, what would you end up
 with?

 # Question 1.a
 def temp(T, from_unit, to_unit):

I suspect that this doesn't work properly for all cases of from_unit, 
to_unit.

As a general case:

def temp ( T, u1, u2 ):
# from and to units the same, return T unchanged
# else use a conversion table
ct = { (a, b):lambda x: formula,  }
return ct[ (u1, u2 ) ]( T )

Note you may need to build in case independence!

 # Question 1.b 
 def comp(T1, u1, T2, u2):

You completely missed the point of my earlier posts, and I suspect the 
reason both these questions were included.

Firstly, consider that if temp (from q1a) works properly you can use temp 
to convert the units of T2 to the units of T1, by calling:

temp( T2, u2, u1 )

q1b can be implemented in one line if temp from q1a works properly!

 # Question 2 
 def P(p_0, t, i):
Amount = P(1 + (i/100))
return P(1 + (t * i/12))

First calculate the annual interest as 1 + fraction where fraction is 
interest % / 100
The calculate the compounded interest as annual ^ years
Finally multiply the compounded interest by the principal

Mathematically:

principal * ( ( 1 + ( period_interest_% / 100 ) ) ^ periods )

Again, this should be possible as a single line function. All you have to 
do is turn the math into python code.

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


Re: JUST GOT HACKED

2013-10-01 Thread Denis McMahon
On Tue, 01 Oct 2013 12:58:50 +0300, Νίκος wrote:

 Just logged in via FTP to my server and i saw an uploade file named
 Warnign html

Yes, so we can add basic internet security to the growing list of 
things you know nothing about:

python programming, etiquette, http, dns, tcp/ip, mimetypes, utf-8, basic 
internet security

And this is just based on the last 30 days of your posts!

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


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

2013-09-30 Thread Denis McMahon
On Mon, 30 Sep 2013 15:51:39 +0100, Mark Lawrence wrote:

 On 30/09/2013 14:51, Grant Edwards wrote:
 On 2013-09-29, ?? nikos.gr...@gmail.com wrote:
  29/9/2013 10:53 , ??/?? Chris Angelico :

 You fail to understand that these code i now use was written with the
 help of regulars here and yes its correct.

 If you're code is correct, then use it and be happy.
 There's no need to bother us if your code is correct.

 Could this be an extremely rare case whereby the original code is 100%
 correct but the problems have been exacerbated by the many suggested
 patches given here being 100% incorrect?

I'm sending you the bill for hospital admission. I laughed so hard I fell 
off of my chair and banged my head!

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-29 Thread Denis McMahon
On Sun, 29 Sep 2013 13:17:36 +0300, Νίκος wrote:

 Στις 29/9/2013 12:50 μμ, ο/η Dave Angel έγραψε:
 ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
 os.environ.get('REMOTE_ADDR', Cannot Resolve) )
 try:
  gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
  city = gi.time_zone_by_addr( ipval )
  host = socket.gethostbyaddr( ipval ) [0]
 except socket.gaierror as e:
  gi,city,host=globals().get(gi, who knows), globals().get
(city,
 Άγνωστη Πόλη), globals().get(host, Άγνωστη Προέλευση)
 
 Hello Dave,
 
 By looking at your code i think that you are tellign the progrma to try
 to gri don't know what the function globals() is supposed to do
 
 but i was thinking more of:
 
 ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
 os.environ.get('REMOTE_ADDR', Cannot Resolve) )
 try:
   city = gi.time_zone_by_addr( ipval )
   host = socket.gethostbyaddr( ipval ) [0]
 except socket.gaierror as e:
   # We need something here to identify which one of the 2 above 
variables
 or even both of them went wrong, and then assign the appropriate value
 to each one of them but i don't know how to write it.
 
 Is there a function that can tell us which variable failed to be
 assigned a value that we can use in order to decide to which variable we
 will

Yes, set the default values first, and overwrite them with the successful 
values when the values are successfully calculated.

This is a very common method used in many programming languages.

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-29 Thread Denis McMahon
On Sun, 29 Sep 2013 14:34:02 +0300, Νίκος wrote:

 Στις 29/9/2013 2:27 μμ, ο/η Dave Angel έγραψε:
 On 29/9/2013 07:14, Νίκος wrote:


 Dave's way though seems better.
 Assign the vars default string and if they get re-assinged correctly
 that would be ideal, otherwise we have already given them the
 defaults.

 ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
 os.environ.get('REMOTE_ADDR', Cannot Resolve) )
 city = Άγνωστη Πόλη
 host = Άγνωστη Προέλευση
 try:
 gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
 city = gi.time_zone_by_addr( ipval )
 host = socket.gethostbyaddr( ipval ) [0]
 except Exception as e:
 print( metrites.py = (%s):  % lastvisit, repr( sys.exc_info() 
),
 file=open('/tmp/err.out', 'w') )

 I'll think i'll stick to this solution.


 But you've put gi back in to the try-block.  If it really belongs
 there,
 then you'd better give it a default value as well. On the other hand,
 if it can't get an exception, you should move it out.
 
 You are right i just put it there because its being relevant to the
 whole geoip things. Givign it a default value will not really help much
 because i'am not printing it later on it just is necessay to poitn to an
 existing geopip file in plcace.
 
 If it fails to be assinged then i will just cat /etc/err/out and see
 that it erred out and then take action to fix it.

Nick, you have now spent 4 days arguing over a minor coding problem that 
you were given solutions to on the first day, primarily because you feel 
that the solutions you are being offend some programming aesthetic you 
have.

I suggest that it's time for you to re-evaluate what you want from this 
ng, and indeed what language you want to code in if your perl minimal 
code possible aesthetic is so important to you.

If you want good python code, then stop telling everyone here that their 
working solutions are wrong and should be more like your dysfunctional 
code, and use the solutions you are given.

If you want to write minimalist perl code, then stop using python and use 
perl.

In either case, you need to stop arguing with people who are offering you 
solutions to your problems solely based on the fact that you don't like 
their coding styles.

You are the one who comes here asking for solutions. Either accept the 
solutions you are offered, or stop asking for them.

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Denis McMahon
On Fri, 27 Sep 2013 12:19:53 +0300, Νίκος wrote:

 This is my code as i have it at the moment:
 
 ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
 os.environ.get('REMOTE_ADDR', Cannot Resolve) ) try:
   gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
   city = gi.time_zone_by_addr( ipval )
   host = socket.gethostbyaddr( ipval ) [0]
 except socket.gaierror as e:
   city = Άγνωστη Πόλη
   host = Άγνωστη Προέλευση

Here is the basic problem: You're trying to do too many things at once in 
a language you don't understand and without any understanding of the 
fundamental underlying concepts of the systems that you're interfacing 
with.

Break the task down into simpler steps and do the steps one at a time:

Calculate ipval

Calculate gi

If ipval is valid, calculate city, else give city a default value

If ipval is valid, calculate host, else give host a default value

Then consider which of the above needs to be contained within a try / 
catch.

Finally, code them as 4 separate units of code, eg:

# instantiate geolocation by ip
gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')

# calculate ipval
try:
ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or 
  os.environ.get('REMOTE_ADDR', Cannot Resolve) )
except ( KeyError, TypeError ):
ipval = some_default

# try and obtain time zone from ip
try:
city = gi.time_zone_by_addr( ipval )
except (error type[s]):
city = Unknown City

# try and obtain hostname from ip
try:
host = socket.gethostbyaddr( ipval ) [0]
except ( socket.gaierror ):
host = Unknown Host

Note that there is nothing special about writing it in as few lines as 
code as possible. Writing it out in a way that is easy to understand and 
follow helps make sure it actually works, and makes it a lot easier to 
maintain in future.

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


Re: card dealer

2013-09-27 Thread Denis McMahon
On Fri, 27 Sep 2013 12:08:33 +, Dave Angel wrote:

 i recall
 writing a shuffle function in C decades ago, which took an array of (52)
 unique items and put them in random order.

Whenever I tried to write shuffles I came up against a fairly fundamental 
limit:

52!  prng states

Granted prngs seem to be better on the importing entropy from elsewhere 
front these days.

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


Re: what is wrong in my code?? (python 3.3)

2013-09-27 Thread Denis McMahon
On Fri, 27 Sep 2013 06:54:48 -0700, dream4soul wrote:

 #!c:/Python33/python.exe -u
 import os, sys 
 print(Content-type: text/html; charset=utf-8\n\n)
 print ('Hello, world!hr')
 print('ранее предусматривалась смертная казнь.')

 I see only first print, second it just question marks in my browser(code
 edited in notepad++ with UTF-8 encode). what is wrong??

Sounds like your browser is ignoring the charset. Can you force the 
browser to utf-8?

What happens if you create a plain html file with the same content and 
send it to your browser?

eg: test.html:
-
Hello, world!hr
ранее предусматривалась смертная казнь.
-

This really doesn't look like a python issue (again).

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Denis McMahon
On Fri, 27 Sep 2013 18:32:23 +0100, Mark Lawrence wrote:

 On 27/09/2013 18:00, Grant Edwards wrote:
 On 2013-09-27, ?? nikos.gr...@gmail.com wrote:

 Sure your method follows the the logic in a straighforward way
 step-by-step but i just dont want to spent almost 20 lines of code
 just to calculate 2 variables(city and host).

 Does your provider charge you per line of code?

 If all that matters is the number of lines of code then use this:

city,host = 0,0

 Only _1_ nice short line of code.

 Happy?


 Classic overengineering, fancy wasting two whole spaces and having such
 long names.  Surely c,h=0,0 is vastly superior?

Why not c=h=0

2 characters (28%) shorter!

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


Re: Help me with Python please (picture)

2013-09-27 Thread Denis McMahon
On Fri, 27 Sep 2013 17:43:42 -0700, jae655 wrote:

 http://imgur.com/E6vrNs4

 Can't seem to be getting an output.

I can't see where your output statements are.

With no output statements, there is no output.

perhaps you want to assign the result of the function call to a variable, 
and then print the variable? Or perhaps not, perhaps you were going to do 
the output some other way?

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


ANN: Lea 1.1 (discrete probability distributions)

2013-09-26 Thread Pierre Denis
I have the pleasure to announce the release of Lea 1.1.

Lea is a Python package aiming at working with discrete probability
distributions in an intuitive way.

It allows modelling a broad range of random discrete phenomenons. Then, it
allows calculating probabilities of events, whether atomic, aggregated or
combined through given operations. A typical example is the probabilities of
the sum of N dice having known, possibly unfair, probability distributions.

Features


Here are the main features of Lea:

- models finite discrete probability distributions
- standard distribution indicators (mean, standard deviation,.)
- arithmetic and logical operators on probability distribution 
- cartesian products, conditional probabilities, joint distributions
- generation of random samples
- open-source project, LGPL license
- pure Python module, lightweight - no package dependency
- probabilities stored as integers (no floating-point biases)

Links
-

Download (PyPi):http://pypi.python.org/pypi/lea
Project page:   http://code.google.com/p/lea/

(with wiki documentation including tutorials, examples and API)

Hoping this could be helpful in this uncertain universe...

Pierre Denis

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

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-26 Thread Denis McMahon
On Thu, 26 Sep 2013 12:56:19 +0300, Νίκος wrote:

 host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
 os.environ.get('REMOTE_ADDR') or  Άγνωστη Προέλευση )

Perhaps you need something that looks more like:

some_value = some_function_of( some_value ) or some_function_of
( some_value )
if some_value:
host = some_function_of( some_value )
else:
host = some_value

or even:

try:
host = some_function_of( some_function_of( some_value ) or 
some_function_of( some_value ) )
except some_error_type [ or some_error_type  ]:
host = some_value

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-26 Thread Denis McMahon
On Thu, 26 Sep 2013 14:25:55 +0300, Νίκος wrote:

 Okey then please tell me, what do you see wrong in it:
 
 socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP')

If os.environ.get('HTTP_CF_CONNECTING_IP') is false

 or os.environ.get('REMOTE_ADDR') 

and os.environ.get('REMOTE_ADDR') is false

 or  Άγνωστη Προέλευση )[0]

The you try and get the host name from the ip address Άγνωστη 
Προέλευση, but Άγνωστη Προέλευση is not an ip address, so you get an 
error.

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-26 Thread Denis McMahon
On Thu, 26 Sep 2013 12:56:19 +0300, Νίκος wrote:

 Its logic is simple and straightforward but too many lines:

There is no too many lines.

 this is much better in my opinion and straighforward also and more clear
 to read ... it doens't work though:

This is just a stupid attitude for a coder to have.

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-26 Thread Denis McMahon
On Thu, 26 Sep 2013 19:58:02 +0300, Νίκος wrote:

 except socket.gaierror as e:
   city = host = UnKnown Origin
 
 But then what if in case of an error i needed different string set to be
 assigned on city and host respectively?

Oh FFS

Are you serious when you ask this?

Simply change:

except socket.gaierror as e:
city = host = UnKnown Origin

To:

except socket.gaierror as e:
city = Unknown City
host = Unknown Host

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


Re: Referrer key missing form os.environ dictionary?

2013-09-25 Thread Denis McMahon
On Wed, 25 Sep 2013 18:16:39 +0300, Νίκος wrote:

 how caom the http_referer thing works ok now but when i just print all
 the key listing of .os.environ ket the http_referer key isnt inside?

That you do not understand this is caused by your failure to understand 
the HTTP protocol. You have been told before, this NG is not networking 
and / or tcp/ip and / or internet protocols 101.

Please go and learn about the network protocols you're trying to interact 
with before you start writing code that interacts with them. The issue 
you are raising here is not a python issue, it is a network protocols 
issue that has nothing whatsoever to do with python.

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


Re: Help with python functions?

2013-09-24 Thread Denis McMahon
On Mon, 23 Sep 2013 19:40:47 -0700, kjakupak wrote:

 Not sure if we've gotten that far in class, considering I don't know how
 to go about doing that.

Which bit aren't you sure about?

(a) adding a same unit conversion to the units conversion program? 
(Actually, this bit isn't needed after all, you can avoid it with a test 
in comp.)

(b) calling temp from comp to establish a common unit?

(c) comparing the returned value of the call to temp with the other temp 
in comp

Question, given the original temp function as previously described by 
yourself, what does the following function f which takes the same params 
as comp do:

def f( t1, u1, t2, u2 ):
if u1 == u2:
return t2
else:
return temp( t2, u2, u1 )

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


Re: Help with python functions?

2013-09-24 Thread Denis McMahon
On Tue, 24 Sep 2013 03:15:23 +, Steven D'Aprano wrote:

 You don't have to use Kelvin. You could use any temperature scale, so
 long as it is the same for both temperatures.

Given that he already has a handy conversion function to call, he should 
be able to convert t2 into the units of t1 if they're in different units 
(2 lines), and then do his comparison (5 lines).

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


Re: Help with python functions?

2013-09-24 Thread Denis McMahon
On Tue, 24 Sep 2013 14:51:31 +, Denis McMahon wrote:

 Question, given the original temp function as previously described by
 yourself, what does the following function f which takes the same
 params as comp do:
 
 def f( t1, u1, t2, u2 ):
 if u1 == u2:
 return t2
 else:
 return temp( t2, u2, u1 )

Hmm, maybe:

if u1 == u2:

should have been:

if u1.lower() == u2.lower():

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


Re: Help with python functions?

2013-09-23 Thread Denis McMahon
On Mon, 23 Sep 2013 15:55:53 -0700, kjakupak wrote:

 As for the next one, so far I've gotten:
 def comp(T1, u1, T2, u2):
 if u1  u2:
 return -1
 elif u2  u1:
 return 1
 else:
 return 0

If the first function you wrote allows you to convert temps in different 
scales to a common scale, then in the second function, you can call the 
first function to convert both temps to a common scale, and compare them.

Adding same scale conversions in the first function might help. In a 
same scale conversion, the input and output units are the same, and the 
output value is the input value.

Then to compare T1 in u1 and T2 in u2, convert them both to a common 
scale (which might be u1 or u2 or some other scale) using your temp 
function, and then compare the resulting values.

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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Denis McMahon
On Tue, 17 Sep 2013 18:17:43 +0300, Ferrous Cranus wrote:

 So cant this be done in python or not?
 or is a mtetr of configuring the MTA? conf file?

Python can not control data that is added to the message after it has 
left the python program. If you want to retain maximum possible control 
of the mail process from within python, you need to use a python module 
that handles the smtp exchange with the destination mta, however even 
then you can not control the content of header lines added by that 
destination mta, which will invariably include the real[1] ip address of 
your system.

[1] The ip address that it is sending ack packets to as part of the smtp 
session, so unless you're using a proxy somewhere, this will be your 
system's ip address. Can't fake it. If the other system doesn't know your 
ip address, it can't send acks, and the tcp session fails.

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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-17 Thread Denis McMahon
On Wed, 18 Sep 2013 00:42:22 +0300, Ferrous Cranus wrote:

 So the foreign MTA tests for real time connectivity with the local MTA
 and it tries to detect a working host and ip address.

No.

I strongly suggest that you stop trying to write software that transmits 
data across tcp/ip networks until you understand how tcp/ip networks 
function. This NG is not a networking for dummies course.

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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-16 Thread Denis McMahon
On Mon, 16 Sep 2013 12:06:06 +0200, Joost Molenaar wrote:

 It's most likely an issue in your local SMTP server's configuration.

I'm not convinced about that. All the evidence is that OPs local mta 
delivers the message to google. I think the issue is that google are 
deciding the message is junk and dropping it in the bit recycling bin.

This is just as likely to be a feature of the random_char(50) subject and 
random_char(500) message text as it is any local mta settings. I have no 
idea what OPs random_char(x) does, but I also see no proof it doesn't 
insert data that's illegal in subject or body. Even if it creates a 
wholly valid message subject and body, it might look like something spammy 
to google.

starttls suggests that whatever his mta is, it's using some form of auth 
to communicate with gmail. It looks like his mail is delivered to the 
google servers.

If he's trying to prove communication works, he might be better off using 
a message subject of test and a message body of this is a test 
message.

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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-16 Thread Denis McMahon
On Mon, 16 Sep 2013 19:23:15 +0300, Ferrous Cranus wrote:

 Τhis si the headers i would like to delete because i dont want them to
 be used when sending mail:

 X-AntiAbuse: ...

 and this too:

 Received:  ..

This is probably your mta, not python, see your mta config. OFF TOPIC IN 
comp.lang.python

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


Re: Tryign to send mail via a python script by using the local MTA

2013-09-16 Thread Denis McMahon
On Mon, 16 Sep 2013 18:02:20 +0300, Ferrous Cranus wrote:

 We need to try it to see if it will work, or perhaps we can alter both
 the hostname and ip address variables on the server to some other values
 so that google will use them too.
 
 It will not detect the real hostname or the real ip this way since both
 values will be not true.

It may however detect that your are presenting an ip and or hostname that 
does not match the host you are connecting with, and increase the spf 
score on the messages to the point that the messages get rejected either 
in the google mta or downstream due to their spf score.

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


Re: Am I not seeing the Error?

2013-08-13 Thread Denis McMahon
On Sat, 10 Aug 2013 22:19:23 -0400, Devyn Collier Johnson wrote:

 I am checking my 1292-line script for syntax errors. I ran the following
 commands in a terminal to check for errors, but I do not see the error.

 JOB_WRITEURGFILES =
 multiprocessing.Process(write2file('./mem/ENGINE_PID', ENGINEPID);
 write2file(SENTEMPPATH, ''); write2file(INPUTMEM, ''));
 JOB_WRITEURGFILES.start()

When I expand this out to one item per line, 

JOB_WRITEURGFILES =
multiprocessing.Process
(
write2file
(
'./mem/ENGINE_PID'
,
ENGINEPID
)
;
write2file
(
SENTEMPPATH
,
''
)
; 
write2file
(
INPUTMEM
,
''
) 
)
;
JOB_WRITEURGFILES.start()

and I wonder (not being familiar with multiprocessing) if perhaps there 
should have been a third ; after the third write2file in the job 
definition.

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


Re: Using sudo to write to a file as root from a script

2013-08-08 Thread Denis McMahon
On Thu, 08 Aug 2013 23:11:09 -0500, Adam Mercer wrote:

 Hi
 
 I'm trying to write a script that writes some content to a file root
 through sudo, but it's not working at all. I am using:
 
   channel = 'stable'
   config_file = '/opt/ldg/etc/channel.conf'
   command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file]
   p = subprocess.Popen(command, stdout=subprocess.PIPE,
   stderr=subprocess.PIPE)
   out, _ = p.communicate()
 
 But it seems as if this isn't doing anything.
 
 I just want to write the contents of the variable channel to the file
 /opt/ldg/etc/channel.conf. But whatever I try just doesn't work. Can
 anyone offer any pointers?

Do you find anything with:

$ grep sudo /var/log/auth.log

(you may need to specify a different log)

Is the process that's trying to use the sudo command allowed to do so 
without a password?

man sudoers

Note - after editing /etc/sudoers you must set the permissions back to 440

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


Re: Python script help

2013-07-30 Thread Denis McMahon
On Tue, 30 Jul 2013 07:49:04 -0700, cool1574 wrote:

 Hello, I am looking for a script that will be able to search an online
 document (by giving the script the URL) and find all the downloadable
 links in the document and then download them automatically.
 I appreciate your help,

Why use Python? Just:

wget -m url

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


[issue18587] urllib raises exception with string in 'errno' attribute

2013-07-29 Thread Denis

New submission from Denis:

On 'connection refused' error urllib creates IOError with wrong arguents:
args ('socket error', error(os-dependent-number, 'Connection refused'))

It results to dirty hacks in Python code like
  'if e.errno == socket error: ...'

instead of traditional

  'id e.errno == errno.ECONNREFUSED: ...'

--
files: pyerror.py
messages: 193878
nosy: denkoren
priority: normal
severity: normal
status: open
title: urllib raises exception with string in 'errno' attribute
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file31075/pyerror.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18587
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2013-07-02 Thread Denis McMahon
On Tue, 02 Jul 2013 10:16:37 +0200, Antoon Pardon wrote:

 I would like people to have that in mind when they try to tell others to
 just ignore the behaviour that bothers them. Maybe it would help them to
 be a bit more patient to those who have trouble following the advise.

It's quite clear that you're more interested in having arguments and 
slinging insults than you are in discussing python. I'm here to discuss 
python.

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


Re: Parsing Text file

2013-07-02 Thread Denis McMahon
On Tue, 02 Jul 2013 13:28:33 -0700, sas429s wrote:

 Ok here is a snippet of the text file I have:
 I hope this helps..
 .
 Thanks for your help

ok ... so you need to figure out how best to distinguish the filename, 
then loop through the file, remember each filename as you find it, and 
when you find lines containing your target text, print the current value 
of filename and the target text line.

filenames might be distinguished by one or more of the following:

They always start in column 0 and nothing else starts in column 0
They never contain spaces and all other lines contain spaces or are blank
They always contain at least one / characters
They always terminate with a . followed by one or more characters
All the characters in them are lower case

Then loop through the file in something like the following manner:

open input file;
open output file;
for each line in input file: {
if line is a filename: {
thisfile = line; }
elif line matches search term: {
print thisfile in output file;
print line in output file; } }
close input file;
close output file;

(Note this is an algorithm written in a sort of pythonic manner, rather 
than actual python code - also because some newsreaders may break 
indenting etc, I've used ; as line terminators and {} to group blocks)

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


Re: Need explanation of this error

2013-07-01 Thread Denis McMahon
On Mon, 01 Jul 2013 02:13:50 -0700, prerit86 wrote:

 I'm new to Python and trying to run a already written code. Can someone
 please explain the error below? And if possible, how do I resolve this?

 ImportError: DLL load failed: The specified module could not be found.

You're missing the dll that provides some function that you're trying to 
use.

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


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

2013-07-01 Thread Denis McMahon
On Mon, 01 Jul 2013 21:18:26 +0200, Antoon Pardon wrote:

 I am not baiting Nikos.

Your opinion, mine differs.

 all I have done in the last two weeks that involves Nikos as a 
 subject is the Don't feed the troll thread 

Calling him a troll is baiting. Please stop.

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


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

2013-07-01 Thread Denis McMahon
On Mon, 01 Jul 2013 20:42:48 +0200, Antoon Pardon wrote:

 How about the following comprimise. 

 Let me know what you think about this.

How about you just ignore him.

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


Re: python game

2013-06-19 Thread Denis McMahon
On Wed, 19 Jun 2013 13:18:49 -0700, jacksonkemp1234 wrote:

 windowSurface.blit(playerImage, player)
 for bear in bears:
 windowSurface.blit(bearImage, bear)

Try changing this to draw the bears first, then the player.

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


Re: python game

2013-06-19 Thread Denis McMahon
On Wed, 19 Jun 2013 13:18:49 -0700, jacksonkemp1234 wrote:

 if moveDown and player.right  WINDOW_WIDTH:
 player.right += MOVE_SPEED

Should this be moveRight instead of moveDown?

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


Re: A certainl part of an if() structure never gets executed.

2013-06-16 Thread Denis McMahon
On Sat, 15 Jun 2013 19:18:53 +0300, Nick the Gr33k wrote:

 In both situations we still have 2 memory units holding values, so hows
 that different?

Consider that each named variable is a pointer to a memory location that 
holds a value. This is one of the ways in that a typed compiled language 
and an untyped scripted language may differ in their treatment of data 
items (or variables).

Consider the following C and Python code:

C:

int a, b;
b = 6;
a = b;

In C, this places the numeric value 6 into the memory location identified 
by the variable b, then copies the value from the location pointed to 
by b into the location pointed to by a.

b is a pointer to a memory location containing the value 6
a is a pointer to another memory location also containing the value 6

Python:

b = 6
a = b

In Python, this first puts the value 6 in in a memory location and points 
b at that memory location, then makes a point to the same memory 
location as b points to.

b is a pointer to a memory location containing the value 6
a is a pointer to the same memory location

Do you understand the difference?

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


Re: Why 'files.py' does not print the filenames into a table format?

2013-06-16 Thread Denis McMahon
On Sat, 15 Jun 2013 22:38:38 +0300, Nick the Gr33k wrote:

 PLEASE take a look, its not a huge code

First, you need to start writing your code to less than 80 columns if 
you're going to keep posting it to usenet. I'm sure I'm not the only 
person who can't be bothered to unwrap it.

Secondly, the code you posted only tells part of the story - it's 
obviously missing either relevant imports or defined functions or 
possibly both.

Third, it would help to see examples of (a) what you expect it to 
generate, and (b) what it actually generates. You obviously have a web 
server available to you - you could put both code (just append .txt to 
the filename) and screenshots from your browser there with no difficulty 
at all and just include links.

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


Re: Why 'files.py' does not print the filenames into a table format?

2013-06-16 Thread Denis McMahon
On Sun, 16 Jun 2013 11:35:12 +0300, Nick the Gr33k wrote:

 TB behaves for me the same way. Any line  80 chars gets a newline. Why
 this is happening? Why not post up to 256 chars in a single line?

Because this is usenet. Read the RFCs if you must know!

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


Re: A certainl part of an if() structure never gets executed.

2013-06-16 Thread Denis McMahon
On Sun, 16 Jun 2013 11:07:12 +0300, Nick the Gr33k wrote:

 On 16/6/2013 9:32 πμ, Denis McMahon wrote:
 On Sat, 15 Jun 2013 19:18:53 +0300, Nick the Gr33k wrote:

 In both situations we still have 2 memory units holding values, so
 hows that different?

 Consider that each named variable is a pointer to a memory location
 that holds a value. This is one of the ways in that a typed compiled
 language and an untyped scripted language may differ in their treatment
 of data items (or variables).

 Consider the following C and Python code:

 C:

 int a, b;
 b = 6;
 a = b;

 In C, this places the numeric value 6 into the memory location
 identified by the variable b, then copies the value from the location
 pointed to by b into the location pointed to by a.

 b is a pointer to a memory location containing the value 6 a is a
 pointer to another memory location also containing the value 6

 Python:

 b = 6
 a = b

 In Python, this first puts the value 6 in in a memory location and
 points b at that memory location, then makes a point to the same
 memory location as b points to.

 b is a pointer to a memory location containing the value 6 a is a
 pointer to the same memory location

 Do you understand the difference?

 Yes and thank you for explaining in detail to me.
 So Python economies(saves) system's memory. Good job Python!

No. Don't read that into it.

For example, in Python

a = 6
b = a
c = 6

a and b point to one memory location that contains the value 6
c points to a different memory location that contains the value 6

Python doesn't point all the variables that have the same value at the 
same location.

 A pointer = a variable that has as a value a memory address a variable =
 a memory address that has as a value the actual value we want to store.

These are really C terms, not Python terms. Stop thinking that C is 
behaving like Python.

 Is this how the thing works?

No.

Python is an interpreted language. C is a compiled language. They present 
very different feature sets to the user. You need to understand this, and 
at the moment you're not doing so.

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


Re: A certainl part of an if() structure never gets executed.

2013-06-16 Thread Denis McMahon
On Sun, 16 Jun 2013 12:59:00 +0300, Nick the Gr33k wrote:

 Whats the difference of interpreting  to compiling ?

OK, I give up!

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


Re: A few questiosn about encoding

2013-06-15 Thread Denis McMahon
On Fri, 14 Jun 2013 16:58:20 +0300, Nick the Gr33k wrote:

 On 14/6/2013 1:14 μμ, Cameron Simpson wrote:
 Normally a character in a b'...' item represents the byte value
 matching the character's Unicode ordinal value.

 The only thing that i didn't understood is this line.
 First please tell me what is a byte value

Seriously? You don't understand the term byte? And you're the support 
desk for a webhosting company?

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


Re: Don't feed the troll...

2013-06-15 Thread Denis McMahon
On Fri, 14 Jun 2013 12:32:56 +0300, Nick the Gr33k wrote:

 I'mm not trolling man, i just have hard time understanding why numbers
 acts as strings.

It depends on the context.

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


Re: Eval of expr with 'or' and 'and' within

2013-06-15 Thread Denis McMahon
On Sat, 15 Jun 2013 10:04:41 +0300, Nick the Gr33k wrote:

 I called my self 'Ferrous Cranus'(this is what a guy from a forum
 initially called me for being hard-headed :-) ) because i'm indeed
 hardheaded and if i believe that 1 thing should have worked in some way
 i cant change my mind easily that it works in another fashon(only if the
 counter-arguments are strong).

Then you need to stop trying to write python code, because you refuse to 
accept how python works, and python is not going to change for you!

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


Re: Pattern Search Regular Expression

2013-06-15 Thread Denis McMahon
On Sat, 15 Jun 2013 10:05:01 +, Steven D'Aprano wrote:

 On Sat, 15 Jun 2013 02:42:55 -0700, subhabangalore wrote:
 
 Dear Group,
 
 I am trying to search the following pattern in Python.
 
 I have following strings:
 
  (i)In the ocean (ii)On the ocean (iii) By the ocean (iv) In
  this group (v) In this group (vi) By the new group
.
 
 I want to extract from the first word to the last word, where first
 word and last word are varying.
 
 I am looking to extract out:
   (i) the (ii) the (iii) the (iv) this (v) this (vi) the new
   .
 
 The problem may be handled by converting the string to list and then
 index of list.
 
 No need for a regular expression.
 
 py sentence = By the new group
 py words = sentence.split()
 py words[1:-1]
 ['the', 'new']
 
 Does that help?

I thought OP wanted:

words[words[0],words[-1]]

But that might be just my caffeine deprived misinterpretation of his 
terminology.

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


Re: Pattern Search Regular Expression

2013-06-15 Thread Denis McMahon
On Sat, 15 Jun 2013 11:55:34 +0100, Mark Lawrence wrote:

   sentence = By the new group
   words = sentence.split() 
   words[words[0],words[-1]]
 Traceback (most recent call last):
File stdin, line 1, in module
 TypeError: list indices must be integers, not tuple
 
 So why would the OP want a TypeError?  Or has caffeine deprivation
 affected your typing skills? :)

Yeah - that last:

words[words[0],words[-1]]

should probably have been:

first_and_last = [words[0], words[-1]]

or even:

first_and_last = (words[0], words[-1])

Or even:

first_and_last = [sentence.split()[i] for i in (0, -1)]
middle = sentence.split()[1:-2]

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


Re: Pattern Search Regular Expression

2013-06-15 Thread Denis McMahon
On Sat, 15 Jun 2013 13:41:21 +, Denis McMahon wrote:

 first_and_last = [sentence.split()[i] for i in (0, -1)] middle =
 sentence.split()[1:-2]

Bugger! That last is actually:

sentence.split()[1:-1]

It just looks like a two.

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


Re: Creating a Super Simple WWW Link, Copy, Paste into Spreadsheet Program

2013-06-14 Thread Denis McMahon
On Thu, 13 Jun 2013 12:28:09 -0700, buford.lumbar wrote:

 Hi, I'm new to Python. Would someone be able to write me and/or to show
 me how to write a simple program that:
 
 1-follows a hyperlink from MS Excel to the internet (one of many links
 like this, http://www.zipdatamaps.com/76180, for e.g.) and then,
 
 2-copies some data (a population number, e.g. 54195) and then,
 
 3-pastes that data back into the same MS Excel spreadsheet, into the
 adjacent cell.

Why do you want to do this in python? I thought visual basic (or a 
variant thereof) was the preferred coding environment for such things in 
ms office?

A quick google finds me vb code to download a url into a string - 
presumably once you've done that you can find the value you want to 
scrape into your spreadsheet.

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


Re: A certainl part of an if() structure never gets executed.

2013-06-14 Thread Denis McMahon
On Wed, 12 Jun 2013 11:54:25 +0300, Νικόλαος Κούρας wrote:

 So, i must tell:
 
 for i, month in enumerate(months):
  print('option value=%s %s /option' % (i, month) )
 
 to somehow return '==' instead of 0 but don't know how.

You could test for (month == 0) instead of re.search('=', month)? 

Or you could try using == instead of i when i is 0

for i, month in enumerate(months):
  if i != 0:
print('option value=%s %s /option' % (i, month) )
  else:
print('option value=%s %s /option' % (==, month) )

But if you couldn't work either of these solutions out on your own, 
perhaps the really important question you need to be asking yourself 
right now is should I even be trying to code this in python when my 
basic knowledge of python coding is so poor?

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


Re: A certainl part of an if() structure never gets executed.

2013-06-12 Thread Denis McMahon
On Tue, 11 Jun 2013 13:20:52 -0700, Νικόλαος Κούρας wrote:

 The above if structure works correctly *only* if the user sumbits by
 form:
 
 name, month, year or month, year
 
 If, he just enter a year in the form and sumbit then, i get no error,
 but no results displayed back.
 
 Any ideas as to why this might happen?

Yes, I know exactly why this is happening.

It is for one of two reasons. You may determine which one using the 
following secret code which I stole from the illuminati in 1836:

import random

reason = { 1: Input data is not as expected by coder, 2: Flow control 
logic not performing as coder expects, 3: Badger Badger Badger Badger 
Badger Badger Badger Badger Mushroom, 4: Please try again, 5: 
Snake, 6: Grumpy cat says fix your own damn code, 7: I'll be 
back }

print reason[ random.choice( reason.keys() ) ]

Note - this only has a small chance of actually doing what you want (ie 
giving a possibly accurate answer), but it sounds as if that's a level of 
precision you're used to working with anyway.

On a slightly more serious note, if you can't apply yourself to debugging 
a case of the program logic isn't doing what I expect for some value of 
program logic that you coded, that may be a hint that:

a) you don't actually understand what the program logic is doing

b) you shouldn't be writing logic so complex that you can't see how to 
debug it

c) your logic is overly convoluted and complex

d) all of the above

So perhaps you need to scrub the logic altogether, and start again taking 
smaller steps.

You could also perhaps do with a lesson in De Morgan's theorem:

not a and not b and not c = not ( a or b or c )

not a or not b or not c = not ( a and b and c )

and sometimes the alternative form is easier to understand

Now, looking at your code here are two important questions:

(1) What is the initial values of name, month and year?
(2) Which block is actually being executed?

Bear in mind that if a branch other than one you expect to be executed is 
executing, the fail condition might not be what you think it is. 
Specifically, is it possible that the code is executing the wrong branch 
and tripping up when it tries to generate or perhaps execute the sql 
statement empty strings, or just not getting any result from the sql 
because of the empty strings?

Hint - take the code from the current file, apply a liberal smattering of 
print statements, and test it for various values of month, year and name.

def test(name, month, year):
print name, month, year ::, name, month, year
if not re.search( '=', name ) and not re.search( '=', month ) and 
not re.search( '=', year ):
print branch 1
elif not re.search( '=', month ) and not re.search( '=', year ):
print branch 2
elif not re.search( '=', year ):
print branch 3
else:
print branch 4

# testing logic for 8 possible input conditions

test(=, =, =)
test(=, =, x)
test(=, x, =)
test(=, x, x)
test(x, =, =)
test(x, =, x)
test(x, x, =)
test(x, x, x)

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


Re: Redirecting to a third party site with injected HTML

2013-06-10 Thread Denis McMahon
On Sun, 09 Jun 2013 10:09:17 -0700, guytamir1 wrote:

 i'm not really sure how to approach this problem..
 hints :)

Let me restate the problem for you:

You want to display a web page to a visitor that exists on a third party 
website, with some of your own html inserted into it.

Setting aside the multitude of ethical, moral, legal and copyright 
issues, the only technical solution I can see that doesn't involve 
hacking the third party website is to scrape the third party website 
using eg curl, modify the html using your scripting environment of choice 
(I'll assume python) either using some form of dom manipulation or string 
manipulation, and then server the modified page to the visitor.

so pycurl and pydom might be good places to start.

Don't forget that you may need to rewrite urls in the scraped document 
for things such as anchors, images, css, javascript etc to point them 
back at the host server, or some script on your server that can obtain 
and serve the appropriate resources.

Alternatively, how about displaying the third party website in an iframe 
within your own document? Although that's not really pythonic, just 
htmlic.

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


Re: Sorting a set works, sorting a dictionary fails ?

2013-06-10 Thread Denis McMahon
On Mon, 10 Jun 2013 03:42:38 -0700, Νικόλαος Κούρας wrote:


 for key in sorted( months.values() ):
   print('''
   option value=%s %s /option
   ''' % (months[key], key) )
 ==
 
 please tell me Uli why this dont work as expected to.

Because inside the for loop, your value 'key' is an item from the sorted 
list of the values part of months. When you use months[key], you're 
trying to look up in months based on the value part, not the key part. 
Calling it key is confusing you.

Try this:

things = { a:1, b:3, c:2 }

for thing in sorted( things.values() ):
print thing

 Prints 1, 2, 3

for thing in sorted( things.keys() ):
print thing

 Prints a, b, c

Now although things[b] is a valid reference because b is a key in a 
key - value pair, things[3] is not a valid reference, because 3 is not a 
key in a key - value pair.

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


Re: AES 128 bits

2013-06-03 Thread Denis McMahon
On Tue, 04 Jun 2013 07:52:17 +0800, usman mjoda wrote:

 Good day everyone, I need assistance for python codes of aes 128 bits
 key that can be run on SAGE Application. Thanks

google pycrypto

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


Re: Create a file in /etc/ as a non-root user

2013-06-01 Thread Denis McMahon
On Fri, 31 May 2013 02:12:58 -0700, BIBHU DAS wrote:

 Any Idea how to create a file in /etc as non-root user?Can i use umask
 or chmod...confused

If you don't have root access, you probably shouldn't be trying to write 
in /etc. If you need to write in /etc, explain to the sysadmin why you 
need root access.

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


Re: How to create new python file with increament number, if doesn't exist?

2013-05-27 Thread Denis McMahon
On Mon, 27 May 2013 02:27:59 -0700, Avnesh Shakya wrote:

 I want to create a new python file like 'data0.0.5', but if it is
 already exist then it should create 'data0.0.6', if it's also exist
 then next like 'data0.0.7'. I have done, but with range, please give
 me suggestion so that I can do it with specifying range.

Try and put your description into the sequence of instructions you want 
the computer follow.

For this problem, my sequence of instructions would be:

1) Find the highest numbered existing file that matches the filename 
data0.0.[number]

2) Create a new file that is one number higher.

Now the solution is easy. Find the list of filenames in the directory 
that match a suitable regular expression, take the numeric value of a 
substring of the filename for each file and find the highest, add one to 
it, then create the new file name.

Something like the following (untested) with the relevant imports etc:

nfn=data0.0.+str(max([int(f[8:])for f in os.listdir(p)if re.match
('^data0.0.[0-9]+$',f)])+1)

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


Re: how to compare two json file line by line using python?

2013-05-27 Thread Denis McMahon
On Sun, 26 May 2013 21:32:40 -0700, Avnesh Shakya wrote:

how to compare two json file line by line using python? Actually I am
doing it in this way..

Oh what a lot of homework you have today.

Did you ever stop to think what the easiest way to compare two json 
datasets is?

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


Re: Reading *.json from URL - json.loads() versus urllib.urlopen.readlines()

2013-05-27 Thread Denis McMahon
On Mon, 27 May 2013 14:29:38 -0700, Bryan Britten wrote:

 Try to not sigh audibly as I ask what I'm sure are two asinine
 questions.
 
 1) How is this approach different from twtrDict = [json.loads(line) for
 line in urllib.urlopen(urlStr)]?
 
 2) How do I tell how many JSON objects are on each line?

Your code at (1) creates a single list of all the json objects

The code you replied to loaded each object, assumed you did something 
with it, and then over-wrote it with the next one.

As for (2) - either inspection, or errors from the json parser.

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


Re: Future standard GUI library

2013-05-27 Thread Denis McMahon
On Tue, 28 May 2013 08:21:25 +1000, Chris Angelico wrote:

 I'll use XML when I have to, but if I'm inventing my own protocol,
 nope. There are just too many quirks with it. How do you represent an
 empty string named Foo?

 Foo/Foo

 or equivalently

 Foo/

 How do you represent an empty list named Foo? The same way. How do you
 represent an empty dict/mapping named Foo? Lemme look up my
 documentation... ah, the same way. Does this seem right to
 you?/JubalEarly

Foo type=list /
Foo type=mapping /
Foo type=string /

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


Re: file I/O and arithmetic calculation

2013-05-23 Thread Denis McMahon
On Thu, 23 May 2013 07:17:58 -0700, Keira Wilson wrote:

 Dear all who involved with responding to my question - Thank you so much
 for your nice code which really helped me.

Hold on a sec? Someone posted code that gave the correct answer to a 
homework question?

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


Re: Myth Busters: % this old style of formatting will eventually be removed from the language

2013-05-22 Thread Denis McMahon
On Tue, 21 May 2013 23:26:58 -0400, Ned Batchelder wrote:

 On 5/21/2013 10:26 PM, Carlos Nepomuceno wrote:

 Since str.format() is quite new, a lot of Python code still uses the %
 operator. However, because this old style of formatting will eventually
 be removed from the language, str.format() should generally be used.

 Is this tutorial outdated or this still an issue?

 That tutorial is out of date.  %-formatting isn't being removed.

Indeed, removing %-formatting could break a substantial amount of live 
code, with potentially significant maintenance effort in the user 
community simply to make existing code work with the new interpreter. The 
effect of this on corporations using python code translates into 
business risk, and the next step is we can avoid the business risk by 
migrating our python scripts to some other language.

For the designers and maintainers of any language to arbitrarily[1] (in 
the eyes of the user base) remove a widely used feature that would have a 
major effect on the user base could kill off a language, simply because 
many users will not want to take the risk of it happening again, even if 
they can easily automate the upgrade from removed obsolete language 
feature to new shiny language feature.

[1] Some portion of the user base will always consider any such change 
that causes them headaches and additional effort as having been 
arbitrary, no matter how well the language designers and maintainers 
explain the need to break the old scripts.

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


Re: file I/O and arithmetic calculation

2013-05-22 Thread Denis McMahon
On Thu, 23 May 2013 01:13:19 +0900, Keira Wilson wrote:

 I would appreciate if someone could write a simple python code for the
 purpose below:

Didn't have your data, so couldn't verify it completely, but try this:

import re
def v(s):
 l=len(s)
 t=0.
 for i in range(l):
  t=t+(abs(ord(s[i]))*1.)
 return t/(l*1.)
for n in range(5):
 m=c:/test/+str(n+1)+.txt
 f=open(m,r)
 d=[]
 t=0.
 for l in range(10):
  d=d+[re.findall(r[0-9.eE+-]+,f.readline())]
  t=t+v(d[l][0])
 f.close()
 c=t/10.
 if c==50.:
  t=0.
  for u in range(10):
   t=t+v(d[0][u])
  r=t/10.
  print %s C1: %f R1: %f%(m,c,r)

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


Re: A computer programmer, web developer and network admin resume

2013-05-21 Thread Denis McMahon
On Wed, 22 May 2013 01:15:27 +, i...@databaseprograms.biz wrote:

 If you would like this in text format instead, please let me know.

What if we don't want it at all?

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


Re: in need of some help regarding my rock paper scissors game

2013-05-13 Thread Denis McMahon
On Sun, 12 May 2013 20:33:44 +0100, Alex Norton wrote:

 'Traceback (most recent call last): File C:\Users\Me\Desktop\testy.py,
 line 174, in bWater.clicked.connect( water_clicked ) AttributeError:
 'int'
 object has no attribute 'clicked'' appears when i run the module.

It looks to me as if bWater is an integer value and doesn't have 
a .clicked attribute.

Where is bWater assigned, and what is it assigned to?

If you have a clickable water widget of some sort in your gui, what is 
the click handler for that widget defined as?

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


Re: Style question -- plural of class name?

2013-05-08 Thread Denis McMahon
On Wed, 08 May 2013 16:20:48 -0400, Roy Smith wrote:

 FooEntry is a class.  How would you describe a list of these in a
 docstring?
 
 A list of FooEntries
 
 A list of FooEntrys
 
 A list of FooEntry's
 
 A list of FooEntry instances
 
 The first one certainly sounds the best, but it seems wierd to change
 the spelling of the class name to make it plural.

I wouldn't use an apostrophe for pluralisation.

The Normal pluralisation of FooEntry would be FooEntries. Who are you 
expecting to read the docstring? English majors, grammar nazis, wikipedia 
editors, programmers, or all 4?

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


Re: repeat program

2013-04-29 Thread Denis McMahon
On Mon, 29 Apr 2013 17:22:28 -0700, eschneider92 wrote:

 How do I make the following program repeat twice instead of asking
 whether the player wants to play again?

You change something in the folowing two lines:

playagain='yes'
while playagain=='yes':

What you change and how you change it is probably your homework task, so 
I really shouldn't tell you any more than that.

Also, I might not be right about where you need to make the change, but 
hey, this is the internet, it must be right, yeah?

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


Re: Pythonic way to count sequences

2013-04-25 Thread Denis McMahon
On Wed, 24 Apr 2013 22:05:52 -0700, CM wrote:

 I have to count the number of various two-digit sequences in a list such
 as this:
 
 mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)]  # (Here the (2,4) sequence
 appears 2 times.)
 
 and tally up the results, assigning each to a variable.  The inelegant
 first pass at this was something like...
 
 # Create names and set them all to 0 alpha = 0 beta = 0 delta = 0 gamma
 = 0 # etc...
 
 # loop over all the tuple sequences and increment appropriately for
 sequence_tuple in list_of_tuples:
 if sequence_tuple == (1,2):
 alpha += 1
 if sequence_tuple == (2,4):
 beta += 1
 if sequence_tuple == (2,5):
 delta +=1
 # etc... But I actually have more than 10 sequence types.
 
 # Finally, I need a list created like this:
 result_list = [alpha, beta, delta, gamma] #etc...in that order
 
 I can sense there is very likely an elegant/Pythonic way to do this, and
 probably with a dict, or possibly with some Python structure I don't
 typically use.  Suggestions sought.  Thanks.

mylist = [ (3,3), (1,2), fred, (peter,1,7), 1, 19, 37, 28.312, 
(monkey), fred, fred, (1,2) ]

bits = {}

for thing in mylist:
if thing in bits:
bits[thing] += 1
else:
bits[thing] = 1

for thing in bits:
print thing,  occurs , bits[thing],  times

outputs:

(1, 2)  occurs  2  times
1  occurs  1  times
('peter', 1, 7)  occurs  1  times
(3, 3)  occurs  1  times
28.312  occurs  1  times
fred  occurs  3  times
19  occurs  1  times
monkey  occurs  1  times
37  occurs  1  times

if you want to check that thing is a 2 int tuple then use something like:

for thing in mylist:
if isinstance( thing, tuple ) and len( thing ) == 2 and isinstance
( thing[0], ( int, long ) ) and isinstance( thing[1], ( int, long) ):
if thing in bits:
bits[thing] += 1
else:
bits[thing] = 1

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


Re: Lists and arrays

2013-04-23 Thread Denis McMahon
On Mon, 22 Apr 2013 11:13:38 -0700, Ana Dionísio wrote:

 I have an array and I need pick some data from that array and put it in
 a list, for example:
 
 array= [a,b,c,1,2,3]
 
 list=array[0]+ array[3]+ array[4]
 
 list: [a,1,2]
 
 When I do it like this: list=array[0]+ array[3]+ array[4] I get an
 error:
 
 TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and
 'numpy.ndarray'
 
 Can you help me?

arr1 = [ 'a', 'b', 'c', 1, 2, 3 ]
# populate a new list with individual members
arr2 = [ arr1[0], arr1[3], arr1[5] ]
# create a new list by adding slices together
arr3 = arr1[:1] + arr1[2:4] + arr1[5:]
print arr2
# output is: ['a', 1, 3]
print arr3
# output is: ['a', 'c', 1, 3]

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


[issue15896] Sporadic EINVAL in nonblocking pipe os.read when forked child fails on Mac OS

2012-09-10 Thread Denis Bilenko

Changes by Denis Bilenko denis.bile...@gmail.com:


--
nosy: +Denis.Bilenko

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15896
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



gevent 0.13.4 released

2011-04-11 Thread Denis Bilenko
Hi!

I'm happy to announce that Gevent 0.13.4 is released.

What is it?

gevent is a coroutine-based Python networking library that uses
greenlet to provide a high-level synchronous API on top of libevent
event loop.

Features include:

   * Fast event loop based on libevent (epoll on Linux, kqueue on FreeBSD).
   * Lightweight execution units based on greenlet.
   * API that re-uses concepts from the Python standard library (for
example there are Events and Queues).
   * Cooperative sockets with ssl support.
   * DNS queries performed through libevent-dns.
   * Monkey patching utility to get 3rd party modules to become cooperative.
   * Fast WSGI server based on libevent-http.

Homepage: http://www.gevent.org/

What's new in 0.13.4?

Gevent 0.13.4 is a maintenance release, fixing a number of bugs in
various modules. Read the full changelog here:
http://www.gevent.org/changelog.html

Get it from PyPI: http://pypi.python.org/pypi/gevent

Cheers,
Denis.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


[issue10496] import site failed when Python can't find home directory

2011-04-01 Thread Denis Barmenkov

Denis Barmenkov denis.barmen...@gmail.com added the comment:

I saw similar error on Python 2.6 installed on freeBSD.
I had test SVN server and wrote pre-commit hook using python. When remote 
developer commited his changes to repository, hook called os.path.expanduser 
and exception was raised:
#  File /usr/local/lib/python2.6/posixpath.py, line 259, in expanduser
#userhome = pwd.getpwuid(os.getuid()).pw_dir
#KeyError: 'getpwuid(): uid not found: 12345'

So its not a just-Linux issue.

--
nosy: +Denis.Barmenkov

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10496
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



gevent 0.13.2 released

2011-01-28 Thread Denis Bilenko
Hi!

I'm happy to announce that Gevent 0.13.2 is released with a number of
bug fixes and
a new gevent.httplib module that implements fast HTTP client - wrapper
around libevent-http.

What is it?

gevent is a coroutine-based Python networking library that uses
greenlet to provide a high-level synchronous API on top of libevent
event loop.

Features include:

   * Fast event loop based on libevent (epoll on Linux, kqueue on FreeBSD).
   * Lightweight execution units based on greenlet.
   * API that re-uses concepts from the Python standard library (for
example there are Events and Queues).
   * Cooperative sockets with ssl support.
   * DNS queries performed through libevent-dns.
   * Monkey patching utility to get 3rd party modules to become cooperative.
   * Fast WSGI server based on libevent-http.

Homepage: http://www.gevent.org/

What's new in 0.13.2?

Read the full changelog here:
http://www.gevent.org/changelog.html

Get it from PyPI: http://pypi.python.org/pypi/gevent

Thanks to Tommie Gannert, Örjan Persson, Alexey Borzenkov. Ralf
Schmitt, Nicholas Piël, Elizabeth Jennifer Myers, Ned Rockson, Jon
Aslund.

Cheers,
Denis.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


[issue10935] wsgiref.handlers.BaseHandler and subclasses of str

2011-01-20 Thread Denis S. Otkidach

Denis S. Otkidach denis.otkid...@gmail.com added the comment:

Phillip, your argument about interfacing with code written in C doesn't work 
for built-in immutable types like str. Any subclass of str must call 
str.__new__ thus keeping proper internal state.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10935
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10935] wsgiref.handlers.BaseHandler and subclasses of str

2011-01-19 Thread Denis S. Otkidach

Denis S. Otkidach denis.otkid...@gmail.com added the comment:

Current behavior is unpythonic: documentation explicitly mentions isinstance as 
preferred way to check type (see http://docs.python.org/library/types.html ).

Also 2.7 is the last minor version with str as main string type. So I believe 
it should use isinstance(val, basestring) to help transition to Python 3.

--
nosy: +ods

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10935
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



gevent 0.13.1 released

2010-09-23 Thread Denis Bilenko
Hi!

I'm happy to announce that Gevent 0.13.1 is released.

What is it?

gevent is a coroutine-based Python networking library that uses
greenlet to provide a high-level synchronous API on top of libevent
event loop.

Features include:

* Fast event loop based on libevent (epoll on Linux, kqueue on FreeBSD).
* Lightweight execution units based on greenlet.
* API that re-uses concepts from the Python standard library (for
example there are Events and Queues).
* Cooperative sockets with ssl support.
* DNS queries performed through libevent-dns.
* Monkey patching utility to get 3rd party modules to become cooperative.
* Fast WSGI server based on libevent-http.

Homepage: http://www.gevent.org/

What's new in 0.13.1?

Gevent 0.13.1 is a maintenance release, fixing a number of bugs in
various modules. Read the full changelog here:
http://www.gevent.org/changelog.html

Get it from PyPI: http://pypi.python.org/pypi/gevent

Cheers,
Denis.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: GUibuilder evaluation

2010-09-06 Thread Denis Gomes
Hello,

   There are really three you can choose from if you are serious about
making GUI applications.  PyQt as already suggested.  wxPython and pyGTK.
 Tkinter is good in my opinion if you are making smaller gui based programs.
 PyQt has an extensive number of additional features, including networking,
OpenGL, Multimedia, Database etc.  It is used for the KDE desktop
environment.   PyQt has a very powerful Designer which you can used to
generate python code very fast for complex guis.  wxPython is only GUI
centric, but it does have a host of widgets you can play with and pre-made
examples you can use to speed up your programming.  It also has a gui
building called Boa Constructor which is functional but not in the same
class as the qt designer (this is my opinion, try it).  As for pyGTK, it is
used for Gnome.  I am not to familiar with it but it looks like a good gui
toolkit as well.  So my advice is to try all three and see which one you
like the best and go from there.

Denis

On Mon, Sep 6, 2010 at 6:15 AM, wissem belguidoum wbelguid...@gmail.comwrote:

 On 6 sep, 09:54, Niklasro nikla...@gmail.com wrote:
  Hello
  Making a GUI, could you recommend tkinter or any other proposal?
  Thanks

 Hi,

 I am considering to learn Qt, which is a multi-platform widget
 liberary and a RAD IDE...,
 basically for C++ programing but there is a binding called PyQt for
 python.

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

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


python+sqlite3 in memory database

2010-08-30 Thread Denis Gomes
Hi Everyone,

I am using sqlite3 with python2.5 and the pysqlite wrapper. I am trying
to copy tables from one database (in memory) to another database (file)
using ATTACH. I looked on the internet and found a couple of sites that show
how to do this but the table schema is not copied.

def SaveToFile(self,filename):
# Attach external db file - give it handle filename
# Attaching automatically creates a database by default
self.__curs.execute(ATTACH %s AS %s % (filename,filename))
table_names=self.__curs.execute(SELECT name FROM main.sqlite_master
WHERE type='table').fetchall()
for table_name, in table_names:
#copy in mem db to persistent db
self.__curs.execute(CREATE TABLE %s.%s AS SELECT * FROM
main.%s % (filename,table_name,table_name))
self.__curs.execute(DETACH %s % filename)  # Detach external db


Is there a way to copy the schema from the sqlite_master table.  I know we
can used iter.dump from within python to dump to text based SQL but I would
prefer not to do this.  Eventually my goal is to dynamically load and unload
sections of a file based database (could be tables or rows) in and out of
memory for effeciency purposes.  Any help is appreciated. Thanks in advance.

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


Re: python+sqlite3 in memory database

2010-08-30 Thread Denis Gomes
Hey Benjamin,

 Take a look at this website I found about cached and in-memory databases.
I think the gist of the article is that caching is good if you are doing
SELECTs on data that is frequently used whereas in-memory speeds up
writes, (inserts and updates) to the db as well as querying. Maybe I am
missing something?

http://www.mcobject.com/in_memory_database

Denis
 http://www.mcobject.com/in_memory_database


On Mon, Aug 30, 2010 at 3:00 PM, Benjamin Peterson benja...@python.orgwrote:

 Denis Gomes denisg640 at gmail.com writes:

 
  Eventually my goal is to dynamically load and unload sections of a file
 based
 database (could be tables or rows) in and out of memory for effeciency
 purposes.

 Have you actually found this to be an useful optimization? SQLite already
 internally caches database information in memory.




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

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


Re: python+sqlite3 in memory database

2010-08-30 Thread Denis Gomes
Yep, I see what you are saying.  I am going to do a bit more research to see
how sqlite3 works internally, ie. cache size, page size, etc, and then
decide if I will need to mess with in-memory databases.

Thanks for your insight, appreciate it.

Denis

On Mon, Aug 30, 2010 at 3:51 PM, Benjamin Peterson benja...@python.orgwrote:

 Denis Gomes denisg640 at gmail.com writes:

 
 
  Hey Benjamin,
 
   Take a look at this website I found about cached and in-memory
 databases.  I
 think the gist of the article is that caching is good if you are doing
 SELECTs
 on data that is frequently used whereas in-memory speeds up
 writes, (inserts and
 updates) to the db as well as querying. Maybe I am missing something?

 Well, of course, but there's little point to doing INSERTs and UPDATEs if
 you
 don't write them to disk at some point. You could just have a long running
 transaction which will not write to the database file (though depending on
 how
 you have sqlite setup it may write to a journal file) until you commit it.




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

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


Re: What is a class method?

2010-08-23 Thread Denis Gomes
John,

   I agree with you and I also think the definition given on the official
python site is somewhat confusing, at least for an engineer like myself.
But I'll take a stab at explaning it using what I know thus far.

  I think to understand what a class method is you have to first understand
what a class variable is.  Take this code snippet for example.

class foo(object):
 x=10
 def __init__(self):
  self.x=20

In this example if you create an instance of foo and call it f.  You can
access the instance attribute x by using f.x or you can access the class
variable using the notation foo.x.  These two will give you two different
results.  Now lets do something a bit more interesting.
Say you have the following snippet.

class foo(object):
 x=0
 def __init__(self):
  self.x=10
  foo.x+=1

f=foo()
g=goo()
f.x
10
g.x
10
foo.x
2

What happened here is that the class variable foo.x is used to keep a count
of the total number of instances created.  So we see that a class variable
can be looked at as what connects the two instances in a way, so that data
can be shared between instances of the same class.  This defintion may very
well only apply to this case, but I think the mechanics is fundamentally the
same.
Keeping this in mind, lets make the jump to class methods.  When an
instance of a class is created, the methods are just functions that work
on the attributes (the variables).  Similarly, a class method is a method
that works on a class variable.  For example,

class foo(object):
 x=10
 def __init__(self):
  self.x=20
 @classmethod
 def change(self):
   self.x=15

f=foo()
f.x
20
foo.x
10
f.change()
f.x
20
foo.x
15

So this is my explanation for what a classmethod is.  Hope it helps.  Good
luck.

Denis

On Mon, Aug 23, 2010 at 2:24 AM, John Nagle na...@animats.com wrote:

 On 8/22/2010 9:16 PM, James Mills wrote:

 On Mon, Aug 23, 2010 at 1:53 PM, Paulo da Silva

 psdasilva.nos...@netcabonospam.pt  wrote:

 I did it before posting ...

 The explanation is not very clear. It is more like how to use it.


 Without going into the semantics of languages basically the
 differences are quite clear:

 @classmethod is a decorator that warps a function with
 passes the class as it's first argument.

 @staticmethod (much like C++/Java) is also a decorator that
 wraps a function but does not pass a class or instance as
 it's first argument.


That reads like something the C++ standards revision committee
 would dream up as they add unnecessary template gimmicks to the
 language.

John Nagle

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

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


[issue8571] zlib causes a SystemError when decompressing a chunk 1GB

2010-05-07 Thread Denis Dmitriev

Denis Dmitriev dmitr...@deshaw.com added the comment:

Is there a reason to keep inplen and max_length ints instead of making them 
Py_ssize_t too? I'm a little worried that keeping them ints will cause a 
similar problem further down the line.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8571
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8571] zlib causes a SystemError when decompressing a chunk 1GB

2010-04-29 Thread Denis Dmitriev

New submission from Denis Dmitriev dmitr...@deshaw.com:

There's a bug in python's zlibmodule.c that makes it raise SystemError whenever 
it tries to decompress a chunk larger than 1GB is size. Here's an example of 
this in action:

dmitr...@...:~/moo/zlib_bug cat zlib_bug.py 
import zlib

def test_zlib(size_mb):
print testing zlib with a %dMB object % size_mb
c = zlib.compressobj(1)
sm = c.compress(' ' * (size_mb*1024*1024)) + c.flush()
d = zlib.decompressobj()
dm = d.decompress(sm) + d.flush()

test_zlib(1024)
test_zlib(1025)

dmitr...@...:~/moo/zlib_bug python2.6 zlib_bug.py 
testing zlib with a 1024MB object
testing zlib with a 1025MB object
Traceback (most recent call last):
  File zlib_bug.py, line 11, in module
test_zlib(1025)
  File zlib_bug.py, line 8, in test_zlib
dm = d.decompress(sm) + d.flush()
SystemError: Objects/stringobject.c:4271: bad argument to internal function

dmitr...@...:~/moo/zlib_bug

A similar issue was reported in issue1372; however, either this one is 
different, or the issue still exists in all versions of Python 2.6 that I 
tested, on both Solaris and Mac OS X. These are all 64-bit builds and have no 
problem manipulating multi-GB structures, so it's not an out-of-memory 
condition:

dmitr...@...:~/moo/zlib_bug python2.6   
Python 2.6.1 (r261:67515, Nov 18 2009, 12:21:47) 
[GCC 4.3.3] on sunos5
Type help, copyright, credits or license for more information.
 len(' ' * (6000*1024*1024))
6291456000


--
components: Library (Lib)
messages: 104522
nosy: ddmitriev
priority: normal
severity: normal
status: open
title: zlib causes a SystemError when decompressing a chunk 1GB
type: crash
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8571
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8571] zlib causes a SystemError when decompressing a chunk 1GB

2010-04-29 Thread Denis Dmitriev

Denis Dmitriev dmitr...@deshaw.com added the comment:

Alright, I think this is caused by the following:

static PyObject *
PyZlib_objdecompress(compobject *self, PyObject *args)
{
int err, inplen, old_length, length = DEFAULTALLOC;
int max_length = 0;

The problem is that inplen, length, old_length, and max_length are all ints, 
whereas they should be Py_ssize_t. I think replacing them should make the bug 
go away. (I can't test it right now though because I'm having trouble compiling 
zlibmodule on my current machine)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8571
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Total maximal size of data

2010-01-28 Thread denis
On Jan 25, 8:05 pm, Alexander Moibenko moibe...@fnal.gov wrote:
 I have a simple question to which I could not find an answer.
 What is the [total maximal] size of list including size of its elements?

Beware, sys.getsizeof(alist) is 4*len(alist) + a bit, regardless of
alists's contents ?!
See 
http://stackoverflow.com/questions/2117255/python-deep-getsizeof-list-with-contents

cheers
  -- denis

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


How to validate the __init__ parameters

2009-12-21 Thread Denis Doria
Hi;

I'm checking the best way to validate attributes inside a class. Of
course I can use property to check it, but I really want to do it
inside the __init__:

class A:
def __init__(self, foo, bar):
self.foo = foo #check if foo is correct
self.bar = bar

All examples that I saw with property didn't show a way to do it in
the __init__. Just to clarify, I don't want to check if the parameter
is an int, or something like that, I want to know if the parameter do
not use more than X chars; and want to do it when I'm 'creating' the
instance; not after the creation:

a = A('foo', 'bar')

not

class A:
def __init__(self, foo = None, bar = None):
self._foo = foo
self._bar = bar
def  set_foo(self, foo):
if len(foo)  5:
 raise something
_foo = foo
foo = property(setter = set_foo)

a = A()
a.foo = 'foo'


I thought in something like:

class A:
def __init__(self, foo = None, bar = None):
set_foo(foo)
self._bar = bar
def  set_foo(self, foo):
if len(foo)  5:
 raise something
_foo = foo
foo = property(setter = set_foo)

But looks too much like java
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue7114] HTMLParser doesn't handle ![CDATA[ ... ]]

2009-12-08 Thread Denis

Denis pyt...@sokolov.cc added the comment:

The CDATA sections are part of XML specification.
http://www.w3.org/TR/REC-xml/#sec-cdata-sect

HTML is not XML, so HTMLParser does the right thing here.

--
nosy: +Denis

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7114
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Organization of GUIs

2009-12-04 Thread denis
On Dec 3, 2:44 pm, Michael Mossey michaelmos...@gmail.com wrote:
 complete VISIBILITY and control of messages ...

is most important: being able to SEE messages (filtered on from,
to, ...)
in a running system really helps to understand it.
Hierarchy does help structure messages coarse/fine,
but visibility is orthogonal to structure
(you can have visible democracy, blind hierarchy, in real life too.)

Visibility has to be built in from the beginning --
wrap all connect() s in a visconnect() that can trace.

Dietmar's shell sounds Right; anyone know of such in PyQt ?

cheers
  -- denis



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


[issue5166] ElementTree and minidom don't prevent creation of not well-formed XML

2009-11-24 Thread Denis S. Otkidach

Denis S. Otkidach denis.otkid...@gmail.com added the comment:

Here is a regexp I use to clean up text (note, that I don't touch 
compatibility characters that are also not recommended in XML; some 
other developers remove them too):

# http://www.w3.org/TR/REC-xml/#NT-Char
# Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | 
#  [#x1- #x10]
# (any Unicode character, excluding the surrogate blocks, FFFE, and 
)
_char_tail = ''
if sys.maxunicode  0x1:
_char_tail = u'%s-%s' % (unichr(0x1),
 unichr(min(sys.maxunicode, 0x10)))
_nontext_sub = re.compile(
ur'[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD%s]' % 
_char_tail,
re.U).sub
def replace_nontext(text, replacement=u'\uFFFD'):
return _nontext_sub(replacement, text)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5166
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



gevent 0.11.1 released

2009-11-15 Thread Denis Bilenko
gevent is a coroutine-based Python networking library that uses
greenlet to provide
a high-level synchronous API on top of libevent event loop.

Features include:

* convenient API around greenlets
* familiar synchronization primitives (gevent.event, gevent.queue)
* socket module that cooperates
* WSGI server on top of libevent-http
* DNS requests done through libevent-dns
* monkey patching utility to get pure Python modules to cooperate

0.11.1 fixes a few bugs:

* Fixed bug in select.select() function. Passing non-empty list of
write descriptors used to cause this function to fail.
* Changed setup.py to go ahead with the compilation even if the actual
version of libevent cannot be determined (version 1.x.x is assumed in
that case).
* Fixed wsgi‘s start_response to recognize exc_info argument.
* Fixed setup.py to look for libevent.dylib rather than .so on Darwin platforms.

Thanks to Ludvig Ericson for contributing the last two items.

Get it on PyPI: http://pypi.python.org/pypi/gevent
Homepage: http://gevent.org/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: PyQT4 user group

2009-10-29 Thread denis
For detailed questions, try
http://stackoverflow.com/questions/tagged/pyqt or pyqt4
(the  or  may have to be escaped as %20or%20 in some browsers.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: efficient running median

2009-10-26 Thread denis
Based on Perreault + Hebert, here's python code for a rather different
algorithm:
- for quantized e.g. 8-bit data
- runs faster for wider windows / slowly changing medians
- no heaps, no trees: the only import is numpy, and even that's not
essential

http://stackoverflow.com/questions/1309263/rolling-median-algorithm-in-c

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


Re: efficient running median

2009-10-20 Thread denis
Yet another link: http://en.wikipedia.org/wiki/Median_filter
-- Perreault + Hebert, Median Filtering in Constant Time,
nice 6-page paper + 400 lines well-documented C code:
http://nomis80.org/ctmf.html
(for 2d images, dropping to 1d must be possible :)

They're also in opencv, which I haven't tried --
http://www.intel.com/technology/computing/opencv
http://code.google.com/p/ctypes-opencv
http://code.google.com/p/opencv-cython

cheers
  -- denis

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


Re: efficient running median

2009-10-19 Thread denis
Folks,
  approximate medians -- would you settle for 49 - 51 %  ? --
open up new possibilities, and there's quite a lot of work on that,
for huuuge datasets.

A class of problems:
from a data stream X1 X2 ... you want, every so often,
a histogram / quantile summary / distribution estimator such that
H approximates the distribution of X, so
median of H(t) ~ median of some of X.
Some parameters of this class:
NH, size of H: 100 = H(p) ~ pth percentile of X
A, how often you want H
window, drop or age old data
runtime, memory of course
accuracy -- in theory, in practice

A histogram viewer in which you can change buckets, colors, zoom,
in REALTIME sounds tantalizing -- fast loop  fast algorithm + slow
loop.
Anyone know of one off-the -shelf, python or anything else ?

Refs:
Manku et al., Approximate medians in one pass with limited memory,
1998, 10p
under http://infolab.stanford.edu/~manku/papers.html
nice tree pictures
they optimize mem (NH * Nbuf) not runtime, and don't window

Suri +, Quantiles on Streams, 2006, 5p, 
http://www.cs.ucsb.edu/~suri/psdir/ency.pdf
~ 20 refs zzz

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


Re: ANN: ActivePython 2.6.3.7 (and PyPM) is now available

2009-10-16 Thread denis
On Oct 7, 2:16 am, Sridhar Ratnakumar sridh...@activestate.com
wrote:
 ...
 This release includes a new packaging tool by activestate called Python
 Package Manager (PyPM).PyPM- currently in beta - is the package

Sridhar, folks,
  the ActivePython FAQ says
While you can install most packages registered in PyPI using the PyPM
client, some packages may not yet be available in the ActiveState
repository

Does that mean that PyPM installs ONLY from the activestate repository
and not from url or .tar.gz or dir/ ?

cheers
  -- denis


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


[issue7101] tarfile: OSError with TarFile.add(..., recursive=True) about non-existing file

2009-10-10 Thread Denis Martinez

New submission from Denis Martinez deuns.marti...@gmail.com:

I have written a server backup script (file attached) which archives a
list of directories with tarfile and uploads the file to FTP. Today, the
script hanged, with an exception:

Exception in thread Thread-1:
Traceback (most recent call last):
  File /usr/lib/python2.6/threading.py, line 525, in __bootstrap_inner
self.run()
  File ./backup.py, line 48, in run
tar.add(file_or_directory, recursive=True)
  File /usr/lib/python2.6/tarfile.py, line 1981, in add
self.add(os.path.join(name, f), os.path.join(arcname, f), recursive,
exclude)
  File /usr/lib/python2.6/tarfile.py, line 1965, in add
tarinfo = self.gettarinfo(name, arcname)
  File /usr/lib/python2.6/tarfile.py, line 1834, in gettarinfo
statres = os.lstat(name)
OSError: [Errno 2] No such file or directory: '/srv/myfile.htdigest'

What I did here is that I removed the htdigest file while the tarfile
was archiving /srv. I haven't managed to reproduce the bug a second time.
It seems normal that tarfile shouldn't fail is this case; maybe it needs
some exception checking around the stat/lstat calls.

--
components: Library (Lib)
files: backup2.py
messages: 93845
nosy: denis
severity: normal
status: open
title: tarfile: OSError with TarFile.add(..., recursive=True) about 
non-existing file
type: behavior
versions: Python 2.6
Added file: http://bugs.python.org/file15098/backup2.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7101
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Most active coroutine library project?

2009-10-09 Thread Denis
On Sep 23, 10:58 pm, Brian Hammond
or.else.it.gets.the.h...@gmail.com wrote:
 On Aug 25, 12:51 am, Denis denis.bile...@gmail.com wrote:

  You can also atgevent

 http://pypi.python.org/pypi/gevent

 Please, please document this!  There are a lot of people who would
 love to use this but give up when they don't find a guide or something
 similar.

I've actually started doing that recently, check out http://gevent.org
Feedback is appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


<    1   2   3   4   5   6   7   >