Re: [BangPypers] (no subject)

2013-09-25 Thread steve

On 2013-09-25 17:21, Dhananjay Nene wrote:
On Wed, Sep 25, 2013 at 7:09 PM, Vineet Naik naik...@gmail.com 
wrote:
On Tue, Sep 24, 2013 at 6:19 PM, Dhananjay Nene 
dhananjay.n...@gmail.comwrote:



On Tue, Sep 24, 2013 at 6:11 PM, Dhananjay Nene
dhananjay.n...@gmail.com wrote:

[..]


which just trashed the ordering of an and followed by a plus 
followed by

an and.



This is a more serious problem particularly if the dict is required 
to be

serialized back to xml.

= = =
TL;DR. Use domain rather than use cases for exploring data structures
especially where they can cause a lot of change later. Semantic
Consistency is important, don't treat it lightly. Impedance mismatch
can be fragile. If feasible, stay away.
= = =



Nice one, Dhananjay ! Thanks for spelling out so clearly what feels
instinctively like common sense at times and is just as easy (and 
seductive)

to forget about, at others.


cheers,
- steve

[...snip...]
___
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] https://github.com/pythonhacker/ladies.py

2013-09-07 Thread steve

Hi,

On Sunday 08 September 2013 01:26 AM, svaksha wrote:

On Sat, Sep 7, 2013 at 4:42 PM, Vinayak Hegde vinay...@gmail.com wrote:

On second thoughts maybe this was the objectionable part

def get_purpose():
  Return the purpose 
 raise AmbiguousMissionError, Mission unclear

Also the URL http://ladiespy.com does not resolve.


Ah, maybe you would like to follow up on your own suggestion and
submit a Bug report :) !?



Also there are python programmers(gender-neutral term) on this list.
Maybe if there are
any issues with attitude, you are better off talking on this list and
educating people


Umm... its not a woman's job to educate men (or anyone else for that
matter) on basic manners. And this isnt his first attempt at humor
either: https://mail.python.org/pipermail/bangpypers/2013-July/009125.html



aaah ! I only just got the joke (in light of the isnt_that_odd function)[1] ! I 
am seeing a pattern here. Interesting. I get a feeling that Anand wasn't even 
trying to be funny. sarcastic is possibly a better word I guess -- but I don't 
know enough to be sure.


cheers,
- steve

[1] guess I'm better at reading code than understanding subtle humor. Good one 
Anand !


___
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] https://github.com/pythonhacker/ladies.py

2013-09-07 Thread steve

Hi,

On Sunday 08 September 2013 01:07 AM, svaksha wrote:

On Sat, Sep 7, 2013 at 4:31 PM, Vinayak Hegde vinay...@gmail.com wrote:

Hi Svaksha,

This can be fixed by sending a mail to the author and in this case,
forking, modifying and asking for a pull request.

Why is there a necessity to name and shame ?


Is'nt Anand Pillai a PSF member? This is hardly what one expects from
a PSF member.



  I did not find anything
derogatory in the code (that I checked).


From, https://github.com/pythonhacker/ladies.py/blob/master/__init__.py

def get_purpose():
  Return the purpose 
 raise AmbiguousMissionError, Mission unclear




FWIW, I'm more intrigued by the isnt_that_odd() function. Maybe the intent is 
not merely being cheeky, there's something deeper that Anand felt strongly 
enough to create this repo ? Should we perhaps discuss that publicly too ?


cheers,
- steve
___
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Question on FTP

2013-08-20 Thread steve

On Tuesday 20 August 2013 05:14 PM, davidsnt wrote:

Can some one please help me to find the best way to do a file upload and
file download to a FTP server in python.



http://bit.ly/KKiEQX

cheers,
- steve

___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] problem with python classes

2013-05-09 Thread steve

Hi,


On Thursday 09 May 2013 09:11 PM, hiharry danny wrote:

i have python 2.7.4..now suppose i have two new-style base classes ,
i.e. class ClassName(object):
and the two base classes are related by __init__ constructor where the
__init__ constructor of one base class is accessed by the __init property
of the other base class , for example :

class ClassOne(object):
 def __init__(self,value):
   self.value = value

class ClassTwo(object):
  def __init__(self,inputvalues):
 self.values = []
  for i in inputvalues:
  self.values.append(ClassOne(inputvalues))

In this last statement, what's the point of iterating over inputvalues ? Do you 
really want to create as many instances of ClassOne as the number of inputvalues 
? Or was that for loop supposed to be something like:


...
for i in inputvalues:
self.values.append( ClassOne(i) )
...


if this be the case , then without using inheritance property of OOP ,i,e,
without creating further new subclasses , how can I access other user
defined methods of ClassOne class via Class Two class. The ouput value will
be returned by a user defined method of ClassTwo but the computation will
be done by a method of ClassOne which is called by the user defined method
of class two ...?

so what will be the solution ?


Umm, firstly there is nothing about the above code that is specific to new style 
classes. Perhaps it would be better if you explained what exactly you are trying 
to achieve with a real example (as in, a proper use case). Although it is 
possible to do what you are requesting by simply doing something like this:


 class ClassOne:
... def __init__(self,value):
... self.value = value
... def real_computation(self):
... self.value += 1
...

 class ClassTwo:
... def __init__(self, inputvalues):
... self.values = []
... for i in inputvalues:
... # - assuming that you wanted to create a bunch of ClassOne
... # instances based on inputvalues and populate self.values
... self.values.append( ClassOne(i) )
... def increment_all(self):
... for i in self.values:
... i.real_computation()
...
 o = ClassTwo([10, 20, 30, 42])
 [ i.value for i in o.values ]
[10, 20, 30, 42]
 o.increment_all()
 [ i.value for i in o.values ]
[11, 21, 31, 43]


...it really doesn't make much sense to do something this way, given the limited 
information you have provided.


cheers,
- steve
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Question on Pattern Matching and Regular Expression

2013-01-07 Thread steve

On Monday 07 January 2013 03:06 PM, davidsnt wrote:

Bangpypers,

Having a little trouble in parsing a file of 702 line appox,

the file is in the format
[...snip...]



Could you show us what you already have done ?

cheers,
- steve
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] wierd class behavior

2012-12-04 Thread steve

On Tuesday 04 December 2012 09:24 AM, Anand Chitipothu wrote:

Python scoping rules when it comes to classes are so confusing.

Can you guess what would be output of the following program?

x = 1

class Foo:
 print(x)


Prints the global x


 x = x + 1
 print(x)

Prints the local x, with the reference to the global x lost in the classes 
scope.



print(x, Foo.x)


prints (1, 2) -- ie: the 'global x' and the class local x. So, does the right 
thing. What were you expecting ?




Now take the same piece of code and put it in a function.

def f():
 x = 1

 class Foo:
 print(x)
 x = x + 1
 print(x)

 print(x)
 print(Foo.x)

f()



Again, global versus local difference for the /class/. Still not sure what you 
were expecting,



To add more to your confusion, try this too:

def g():
 y = 1
 class Foo:
 y = 2
 def gety(self):
 return y

 foo = Foo()
 print(y, foo.y, foo.gety())

g()

Ok, this is slightly confusing but still consistent. You'd understand the source 
of your confusion if you changed the definition for gety() to:

...
...
def gety(self):
return self.y
...
...



Does it make any sense?

Well, it does if you know the rules.

http://effbot.org/pyfaq/what-are-the-rules-for-local-and-global-variables-in-python.htm

Try this:

x = 1
class Foo:
print(x)  # this is the global x
x = x + 1 # this is the local x
print(x)
global x  # now lets be explicit
print(x, Foo.x)

what happened here ?

cheers,
- steve

___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Charging state of windows machine (laptop/notebook)

2012-10-31 Thread steve

On Wednesday 31 October 2012 03:01 PM, Nitin Kumar wrote:

This link is linux specific. I am looking for windows OS machine.


I suspect this would involve doing some low-level interaction with the acpi 
driver on windows. A quick search didn't show up any generic acpi python module 
for windows but you can get an idea of what could be involved for example from:



http://www.thinkwiki.org/wiki/Python_script_for_Windows_to_control_ThinkPad_features

I'd recommend searching for acpi+python+windows or some combination thereof

cheers,
- steve



On Wed, Oct 31, 2012 at 2:41 PM, Prashant Gaur
91prashantg...@gmail.comwrote:



http://www.masnun.me/2010/09/01/python-script-to-monitor-laptop-battery-charge-ubuntulinux-mint.html





On Wed, Oct 31, 2012 at 2:32 PM, Nitin Kumar nitin.n...@gmail.com wrote:



Hi All,

Is there any module in python which can be used to track the charging

state

of laptop (on windows) like its on battery or on power or standby mode?

-- Nitin K ___ BangPypers
mailing list BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers





-- Prashant Gaur +91 9717353657
___ BangPypers mailing list
BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers







___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] hook file download

2012-09-07 Thread steve

Hi,

On Friday 07 September 2012 03:59 PM, Nitin Kumar wrote:

Say for example:

from a site  http://www.winzip.com/downwz.htm we click download button.
So i file download will start.
but I want to do some other activities before file start to download. so is
there a way to pause start of download do some activity and then start the
download using python.

Hope this time I am bit clear.



Not entirely. What exactly are you trying to achieve ? If you are trying to do 
this as part of testing, take a look at Selenium ( http://seleniumhq.org/ ) or 
mechanize ( http://wwwsearch.sourceforge.net/mechanize/ ). If, otoh, you are 
trying to automate something using a browser (as opposed to doing it from the 
command line, for instance using twill - http://twill.idyll.org/ ) then I'd 
suggest using javascript or creating/hacking an existing download manager extension.


hth,
cheers,
- steve

...snip...
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Need help understanding -9 1

2012-07-02 Thread steve
Hi,

On 06/29/2012 04:03 PM, Anand Chitipothu wrote:
 On Fri, Jun 29, 2012 at 3:40 PM, Varun Narang varunar...@gmail.com wrote:
 Hi all,

 I need some help understanding the right shift operation on -9. To my
 understanding, it's represented as -0b1001, Now, if I shift it one place to
 right, it should give me -0b0100, which is decimal equivalent of 4. but
 running this on python console gives me -5.

 Please help me out here.
 
 -9 is represented internally as 0xFFF7.
 
 The last byte in binary is 0111. When on rightshift, it becomes
 1011. Which is 0xFFFB, hex representation of -5.
 
 Try this to see how -9 and -5 are represented internally:
 
 import ctypes
 libc = ctypes.CDLL(libc.so.6)
 a = libc.printf(%x\n, -9)
 fff7
 a = libc.printf(%x\n, -5)
 fffb
 
 This works only on linux.


btw, one doesn't need to use ctypes for this. Just coincidentally, a while back
I was wondering why I couldn't use the builtin hex() to represent negative
numbers in python and learned that one has to limit the integer to 32 bits for
this to work correctly. ie:

 hex(9)
'0x9'
 hex(-9)
'-0x9'
 hex(-9  0x)
'0xfff7'


I got this from :
http://stackoverflow.com/questions/3831833/printing-negative-values-as-hex-in-python

cheers,
- steve

-- 
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] log and figure out what bits are slow and optimize them.

2012-02-14 Thread steve
Hi,

If it's a production website you might want to look at NewRelic. We started
using it a while back and it has been mighty helpful:

http://newrelic.com
http://newrelic.com/docs/python/new-relic-for-python

cheers,
- steve

On 02/12/2012 08:09 PM, Anand Chitipothu wrote:
 2012/2/12 Saju M sajup...@gmail.com:
 Hi,
 I wrote a decorator using cProfile.
 Issue is log-file getting messed up with logs of unwanted method
 calls(library calls).
 I tried with prof.getstats() and prof.print_stats(), prof.getstats() force
 to code extra loops to get infos.
 I am also planning to enable/disable this logging using DEBUG flag.

 Have any suggestions to improve this code ???  or  any other-way ??
 
 Since you are doing this in a webapp, you should be able to write a
 WSGI middleware that enables the profiler if profile=true is passed as
 query parameter.
 
 I found this technique very useful to optimize webapps. Here is an example:
 
 http://openlibrary.org/books/OL1M/Kabit%C4%81.?_profile=true
 
 web.py has a nice profile middleware, it shouldn't be too hard to reuse it.
 
 https://github.com/webpy/webpy/blob/master/web/http.py#L140
 https://github.com/webpy/webpy/blob/master/web/utils.py#L1070
 
 Anand
 ___
 BangPypers mailing list
 BangPypers@python.org
 http://mail.python.org/mailman/listinfo/bangpypers


-- 
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] golf problem

2011-12-25 Thread steve
Hi,

On 12/25/2011 12:52 PM, Kenneth Gonsalves wrote:
 hi,
 
 a golf course has 18 holes. There are three types of hole - par 3, par 4
 and par 5. For a certain type of tournament it is necessary to generate
 a random list of 6 holes. The only condition is that this list should
 contain at least one of each type of hole. What would be an elegant way
 of doing this. Sample data for Ooty golf course is given below. The hole
 number is the first element of each tuple and the par is the second
 element.


I am sorry, I didn't quite understand this bit it is necessary to generate a
random list of 6 holes., since the list below has 18 elements. In any case,
whether you need 6 or 18 -- the simplest way to do this would be:

 l = []
 for i in range(6):
... l.append(random.choice([3,4,5]))
...
 l
[4, 5, 3, 4, 5, 5]

# ...where the index is the hole number and the element is the par, or if you
# need it in the format you showed:

 l = []
 for i in range(1, 19):
... l.append((i, random.choice([3,4,5])))
...
 l
[(1, 5), (2, 3), (3, 4), (4, 5), (5, 3), (6, 3), (7, 5), (8, 4), (9, 3),
(10, 5), (11, 5), (12, 5), (13, 4), (14, 5), (15, 3), (16, 5), (17, 3), (18, 5)]


cheers,
- steve

-- 
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] scanf replacement in python

2011-11-07 Thread steve

On 11/06/2011 11:59 AM, kracekumar ramaraju wrote:

Hello

The question might  be simple, but it has a trick.
*
*
*c code*
*scanf(%d, %d,m,n)*

The code can accept two nos separated by a space.

*Question*: What is the equivalent in python?

*Answer 1:*
*p*

*Shortcoming*: I need press return to get o/p of second no.



Umm, isn't that the case with C too ?


*Answer 2:*
a = raw_input(no; )
#Enter two nos separated by space
a = a.split()

*Shortcoming*: it involves split function.

Is there any better way to approach the same problem.



http://effbot.org/pyfaq/is-there-a-scanf-or-sscanf-equivalent.htm
http://docs.python.org/library/re.html#simulating-scanf
http://stackoverflow.com/questions/2175080/sscanf-in-python

cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] File read

2011-11-07 Thread steve

Hey Shashidhar,

Others may answer your question, I am not going to do that right away. I'll just 
offer a few suggestions to clean up your code. If you do that, I promise to 
answer your questions:


a. Use os.path.join() to join path components

b. You don't /have/ to read all the lines of the file into a list before 
processing it. The pythonic way would be:


with open(filename) as input_file:
for line in input_file.readline():
...do stuff ...

c. You don't need to iterate over lists using numeric indexes. Even if you 
/need/ numeric index, use enumerate. So, instead of :


for index in range(len(somelist)):
...do something with somelist[index] ...
OR
...do something with index ...

use something like:

for element in somelist:
   ...do something with element...
OR
for index, element in enumerate(somelist):
   ...do something with index or element 


d. Don't chain string operations to just match a substring, use regular 
expressions. If you /have/ to chain string operations (for instance, to extract 
rather than match), chain them only once. So, instead of :


if all_lines_in_file[line].split('-')[1].split(')')[0].split(')[1].strip() == 
true:

...
...
 print ZMP value %s % 
all_lines_in_file[line].split('-')[1].split(')')[0].split(')[1].strip()


...and more such monstrosities, do either:

stuff_that_interests_me = line.split('-')[1].split(')')[0](')[1].strip()

if stuff_that_interests_me == 'true':


or just:
matched = re.search(-\((.*)\), line) # or some such, depending on the format

if matched:
stuff_that_interests_me = matched.group()


e. If you need one of three options as values of a dict (which I assume will 
serve as a config dict), default the config keys to something. So, do:


config = {'MyFirstKey' : 'ASK',
  'MyNextKey'  : 'ASK',
  ...
  }

for line in all_lines:
...extract stuff_that_interests_me from line...
if 'MyFirstKey' in line:
if stuff_that_interests_me == 'true':
config['MyFirstKey'] = 'ON'
elif stuff_that_interests_me == 'false':
config['MyFirstKey'] = 'OFF'
...


HTH,
cheers,
- steve


On 11/07/2011 05:17 PM, Shashidhar Paragonda wrote:

Dear Python hackers,

   I have text file. I read each line and store it in List.

   my requirement is I need to check only  6 special lines from i.e

   1. resultToPDFFile
   2. resultToPDFFileDialog
   3. resultToQdasFile
   4. resultToQdasFileDialog
   5. resultToTableFile
   6. resultToTableFileDialog

  Note: each line have value set in the end eg:  resultToPDFFile '-' true

   my conditions are:
if first line mentioned above found check the value if it true
  set dictionary item D['PDF'] = ON
else if value is not true then
check for line resultToPDFFileDialog if value is off
   set dictionary item D['PDF'] = OFF
else:
  set dictionary item D['PDF'] = ASK

for example these are the lines in file:

resultToPDFFile  '-' 'true'

 resultToPDFFileDialog  '-'  'on'

I have put if else condition statements exactly same as I mentioned
above.
now my problem is though the resultToPDFFile is true
first time I get the value as ON for dictionary item D['PDF']
When loop starts for finding other lines i.e numbers 3  4 from
above list my Dictionary   item D['PDF'] is becoming ASK
the loop is entering into last else part.
what is problem I am not gotting
is my if else structure is wrong or not I am totally not getting
other idea please help
thank you in advance.

the code is:





 inspset_file_pointer = open(%s/%s % (self.inspsetfile_path,
self.inspection_file),  r)
 # Read all lines from the INSPSET file from the TEMPORARY
directory path
 all_lines_in_file = inspset_file_pointer.readlines()
 inspset_file_pointer.close()
 # loop through all the lines from the file
 print readlines from the file
 for line in range(0, len(all_lines_in_file)-1):
 time.sleep(.5)
 if measPointsForLaterEval in all_lines_in_file[line]:
 print ZMP line found %s % all_lines_in_file[line]
 if
all_lines_in_file[line].split('-')[1].split(')')[0].split(')[1].strip()
== true:
 time.sleep(.3)
 print all_lines_in_file[line]
 print ZMP value %s %
all_lines_in_file[line].split('-')[1].split(')')[0].split(')[1].strip()
 self.cnc_parameters['ZMP'] = ON
 print dictionary values in ZMP %s %
self.cnc_parameters
 exit
 elif measPointsForLaterEvalDialog in
all_lines_in_file[line]:
 if
all_lines_in_file[line+1].split(')')[0].split('#')[1] == off:
 time.sleep(.3

Re: [BangPypers] How to create HTTPS Proxy server

2011-10-09 Thread steve

Hi,

On 10/07/2011 06:31 PM, deepak gupta wrote:

Hi All,

Do any one know , how to create reverse proxy server over HTTPS?

We want to create one HTTPS proxy server:

1. Proxy server (192.168.1.1) : HTTPS port (8000) binding on this server and
user will access this server and browse some url's.for ex
https://192.168.1.1:8000/xyz



2. This (proxy) server 192.168.1.1 will talk to another web server actual
backend server (192.168.1.2: 8000) over HTTP/HTTPS . HTTPS proxy server will
forward the request to the backend server and get back the response and then
return to client browser.

We have created but it is hanging and sometime not returning full data.If
anyone knows any stable proxy server over HTTPS then please let me know.



Could you give some more details ? Like, OS, webserver, and app. server you are 
using ? I recently had to do this using Apache with mod_wsgi on Linux and it 
turned out easier than I assumed initially.


If yours is a similar setup, it basically boils down to just these few 
directives on your proxy:


# Setup SSL
SSLEngine On
SSLCertificateFile /path/to/your/ssl/cert
SSLCertificateKeyFile /path/to/the/private/key

# Turn on Proxying for SSL
SSLProxyEngine On

# Prevent Apache from acting like a forward proxy
ProxyRequests Off

# Map proxy URLs to backend server URL
ProxyPass / https://192.168.1.1:800/

# Ensure that responses from the backend server have correct
# headers when being returned
ProxyPassReverse / https://192.168.1.1:8000/


Note:

a. I've assumed here that you know how to enable and load modules and do the 
rest of the virthost setup. One non-intuitive thing is you'd have to enable both 
mod_proxy and mod_prox_http to make this work.


b. The same can also be achieved with RewriteRules, which is terser and more 
flexible (for example, conditional proxying), explaining that tho' would take 
more time so please send details first.


cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] The myth of free software

2011-05-18 Thread steve

Hi Anand,

On 05/18/2011 01:03 PM, Anand Balachandran Pillai wrote:

Dude, you seriously have lots of free time on your hands... Here is what
I (used to) do when I had time to waste as you do.



Don't feed the troll. I remarked at the fact that this person was deliberately 
trolling in another reply in this thread. Take a look at the URL in his sig and 
then see the pattern of his mails. Someone who lists open source software on his 
homepage (Apache License, even!) and then comes here to rant about the 'myth' of 
free software is obviously trolling (even if he sucks at doing that properly!)


cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] The myth of free software

2011-05-17 Thread steve

On 05/16/2011 08:22 PM, Santosh Rajan wrote:

[...snip...]
So my question is, what shit are you talking about based in India? Please,
Please Enlighten me?




/me thinks somebody just discovered a document online describing the art of 
trolling and now is aspiring to master it. It is fairly obvious given the first 
post and the subsequent responses.


cheers,
- steve



--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


[BangPypers] ZODB in the browser ! ..and yes it's a April fool's day joke ..ehe, wait a sec !

2011-04-04 Thread steve

Hello,

Some people are crazier than their ideas :) ..case in point:

http://davisagli.com/blog/the-making-of-zodb.ws

Excerpt:
On April 1st Matthew Wilkes and I announced the launch of ZODB Webscale Edition, 
which runs the ZODB in a Javascript-based Python interpreter backed by HTML 
localstorage. It was of course in honor of April Fool's day, as the entire 
concept of running the ZODB in a browser is a bit silly, but the technology 
actually works. Here's how we did it.


For those of you who are new to it, ZODB was the best NoSQL DB out there long 
before the term NoSQL was invented.


cheers,
- steve
--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Regarding Python Doc

2011-02-18 Thread steve

On 02/18/2011 03:51 PM, Shashidhar P wrote:

Hello I want to do python documentation, I am using Pydoc but I am unable to
write python documentation for python file.
I have included docstrings for each classes and functions which I have
written. but when I run this command
@ pydoc myfilename.py
it shows no documentation for 'myfilename,py'
can anyone suggest me how to proceed.


When the argument is without a path component, then pydoc searches for the file 
in the current PYTHONPATH. So if your $CWD is not in PYTHONPATH you'd have to say:


pydoc ./myfilename.py

cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] [JOB] Python developer required in Pune with web development experience

2011-01-14 Thread steve

On 01/14/2011 03:46 PM, Anand Balachandran Pillai wrote:

On Thu, Jan 13, 2011 at 11:39 AM, Baishampayan Ghoseb.gh...@gmail.comwrote:


   This interesting job comes with industry competitive compensation.
 
   how much? I wonder why in India people never mention salary range.

 One reason for not stating the actual range and just saying according
 to industry standards is that there is no such thing as a standard
 compensation. The actual pay differs with the person, the role  the
 company. Nevertheless, it's a nice way of saying we won't
 short-change you.



Good point. Industry standard is just euphemism and
an urban myth, no such thing exists :)



Like most standards. Thanks, I'll be here all week !

cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] MetaClass in python

2011-01-12 Thread steve

On 01/12/2011 09:13 PM, Nitin Kumar wrote:

Hi Taj,

On Wed, Jan 12, 2011 at 3:43 PM, Sirtaj Singh Kangsir...@sirtaj.netwrote:



 On 11-Jan-11, at 8:47 PM, Nitin Kumar wrote:
 [snip]

  So i do know who to create a class and its function dynamically at

 runtime???



 You can dynamically create a class like this:

 NewClass = type('NewClass', (object,), {})

 where 'NewClass' is the name of your class, (object,) is any tuple of
 superclasses and *{} will be the __dict__ of the new class*. As steve
 mentioned earlier, you can



So {} can contain function also for the new class, if then can you give
example for the same. As i need function to class being generated.



Namespaces in python are basically dicts ...

[steve@laptop ~]$ python
Python 2.7 (r27:82500, Sep 16 2010, 18:02:00)
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type help, copyright, credits or license for more information.
 
  class A:
... def m(self):
... pass
...
  A.__dict__
{'__module__': '__main__', 'm': function m at 0x7f08629af398, '__doc__': None}
  a = A()
  dir(a)   # the keys of __dict__ of the `object`
['__doc__', '__module__', 'm']
  dir(A)   # the keys of __dict__ of the `class`
['__doc__', '__module__', 'm']
 

So, if you want to create a new function and replace it, use the method I showed 
earlier, or if you really need to create a new class you can use the approach 
that taj showed, basically something like this:


  class foo(object):
... pass
...
  def method(obj, arg):
... print do something with %s passing arg %s % (obj, arg)
...
  NewClass = type('NewClass', (foo,), {'callme' : method})
  a = NewClass()
  a.callme(argument to a)
do something with __main__.NewClass object at 0x7f08629aa610 passing arg 
argument to a

 

I haven't yet looked at the unittest example that you gave because to be honest, 
I'm sorry, I didn't quite understand what you said on first reading.


I'll take a closer look sometime today and reply if possible, however, basically 
all that your really need to understand is a `metaclass` is basically something 
that creates a new object (which is a class) with a nicely customized dict. That 
is to say ...


# if ...
A = MetaClass()

# you have the ability to say ...
a = A()

# and also say ...
a.some_method()

# because MetaClass created A.__dict__ to contain ...
{'some_method':function some_method, ...}


cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] MetaClass in python

2011-01-11 Thread steve

Hi Nitin,

On 01/11/2011 01:15 PM, Nitin Kumar wrote:

Hi all,

I am trying to create one meta Class which can create classes at runtime.
This I am able to achieve by the code snippet below

[...snip...]
but I am looking for one function for this class created above, which will
do some activities (say print some data) at run time.
what all changes can be added to MetaClass to achieve this??

or is there any better way for the same.

The above things I am doing to replace one existing class and its function
attribute depending on some condition. So I want to create new class itself
using MetaClass (bcoz there can be various class which need to be created at
runtime)



Taking one step back can you describe what exactly are you trying to do and why 
do you think Metaclasses are the way to do it ? Maybe there is an existing 
Design Pattern to solve your problem. If you simply wanted to change a method 
for a class you can do it by:


[st...@laptop ~]$ python
Python 2.7 (r27:82500, Sep 16 2010, 18:02:00)
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type help, copyright, credits or license for more information.
 class UpdateMe:
... def replace_me(self):
... print Not replaced
...
 a = UpdateMe()
 a.replace_me()
Not replaced
 def replacement(the_object):
... print Replaced
...
 UpdateMe.replace_me = replacement
 a.replace_me()
Replaced


(hehehe, voice in my head just said Python is dyna-effing-mic, bi***es !!)

cheers,
- steve
--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Suggestion for GUI

2011-01-10 Thread steve

Hi,

You already got the reply to your question so feel free to ignore this.

On 01/10/2011 10:05 PM, Narendra Sisodiya wrote:

On Mon, Jan 10, 2011 at 9:33 PM, Venkatraman Svenka...@gmail.com  wrote:

[...snip...]


My experience in this community  -- You 90% sucks 90%



I do not understand what that meant ^^^. Are you trying to say this community is 
hostile ?



* Yup I made mistake by replying bottom posting but that's ok. If you Google
search on my name blah blah blah [...snip...]infact I keep
on instructing others So its better not to give lecture on everybody..


It doesn't matter who you are and what you've done before if you've committed a 
mistake. The gracious thing to do when someone points out your mistake is to 
accept it an apologize. If that is too much effort, just don't say anything and 
move on, being careful not to do commit the mistake again.




* May of you were kinds enough that you started explaining me fundas of
License Copyright and other things. Who the hell asked about all this.


You did AFAICT:

 http://mail.python.org/pipermail/bangpypers/2011-January/005610.html

quoting:

That's exactly I want to understand. Let take a fictitious example
[...snip...]
I want to understand the benefit/advantage of buying commercial license for
PyQT.




In fact, afaict from your responses of coming up with imaginative fairy-tale 
scenarios where your code spits out valid PyQt which your users then may use 
after downloading GPL'd PyQt (did I get that right ?) I might even say you are 
trolling.




I will ask my query on company's email id and will forward to this mailing
list but I would to say again... Please always reply what somebody is
asking.. Even though you are trying to help by reply but actually you
discourage and irritate people..



I did not see one thing that would be perceived as discouraging or irritating to 
anyone who does not have a egoistical 
'you-don't-know-who-I-am-and-what-I've-done-and-I-don't-need-you-to-explain-me-stuff-I-already-know' 
attitude. Please take a deep breath and re-read the responses. They were all 
polite (maybe tongue-in-cheek; I don't remember, but polite nonetheless).


A lot of time, a lot of people (me included) just reply to content, without even 
bothering to check the name of the sender. So, if they include something that 
you already know about, it is not out of condescension but just because of the 
programmer trait of being complete as well as concise.


hth,
cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Suggestion for GUI

2011-01-10 Thread steve

Hi,

On 01/11/2011 12:27 AM, Narendra Sisodiya wrote:

On



 In fact, afaict from your responses of coming up with imaginative

 fairy-tale scenarios where your code spits out valid PyQt which your users
 then may use after downloading GPL'd PyQt (did I get that right ?) I might
 even say you are trolling.



 See, I wrote a clear fictitious example -- and I asked for help/discussion
 on that but people started talking in-general and teaching license classes.
 this irritated me.



Well, in that case the irritation stems out of your misunderstanding of /why/ 
they were speaking of licenses. To aid your understanding of the implications of 
the license were being demonstrated by comparing different licenses.



 I said -  I am writing my a code which is close source and I have not given
 any rights to user. {i am against it but I am just making an example}
 Now, I am not distributing PyQT to users. All I am given a close source
 application which won't run without PyQt.


Here in lies the problem. When you distributed your PyQt based closed source 
application, you have already distributed PyQt ! ...since at somepoint in your 
code you are calling 'import PyQt' and AFAIK all tools that convert python code 
to an binary 'exe' format essentially create some sort of isolated python 
environment including just the modules required and then compress it up as a 
self-extracting and installing executable.



Users are downloading PyQT.


This will not be used by your closed source binary because the binary will use a 
custom python (think in terms similar to virtualenv) with a custom PYTHONPATH.



 So In this process did I made any copyright infringement... I was expecting
 yes or no kind of answer.


The answer then is yes.


 I gave a clear example.. I am unable to notice any copyright infringement
 in it.



...well there is and this is where the discussion about PyQt GPL Vs PySide's 
LGPL is relevant.





I was asking like this - how does it matter Compiler I am using , I can use
Propitiatory License IDE too - I can license my code to any license at my
will. How the decision of my code's license depends on Compilers License.
for me libraries are also a tool. I am just using them for code building. As
long as I am not giving a bundled close solution to user, I need not to
worry about commercial license to do it. But I am not bundling them.


You should learn how libraries work. Libraries are not just a compile time 
thing. When you 'link' against a library, the binary gets a reference to where 
to 'load' the library at runtime. This is the reason why even if you don't 
intend to do devel work, you cannot run some applications in linux without 
installing the dependent libraries (as opposed to when you do intend to do devel 
work, you install the -devel packages).


(dodging the pedants: yes I know of static linking but I am trying to keep it 
simple here).


So, when you distribute a close source python app., your exe will also include 
the library that your application needs to load at runtime.



, I am
just giving my application to some license, how does this decision depends
on license of libraries. I might be wrong at some where in my fundas or
unable to grab the requirement that why should one buy commercial license
of PyQt. So  I  asked this question. I think it was very much clear from my
post . If not, one can ask to clarify what I want to know..
Posting/Replying on  what license to use, what license gives what and one
can sell GPL code too etc and so many other things some guys replied. That
gave me strong irritation.


I hope my reply didn't give you strong irritation. If what I wrote made sense to 
you go back to the thread and re-read it, you'll see a natural flow there about 
the discussion based on the assumption that you know how libraries work.


cheers,
- steve
--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


[BangPypers] [X-Post] [JOB] Fwd: WebApp requirement @ GSLabs, Pune

2011-01-07 Thread steve
Sorry about the cross-post but I assume that might be people outside Pune who 
may be interested.


I'm forwarding this mail on behalf of someone I know. People interested in this 
may please contact Mr. Harsh Vardhan (consultdadoo at gmail.com) directly.


The job is based in Pune AFAIK.

cheers,
- steve

 Original Message 
Subject:WebApp requirement @ GSLabs, Pune
Date:   Fri, 7 Jan 2011 14:39:23 +0530


*Must have:*
Strong knowledge of web application development in C/C++/Python/Django.

*Good to have:*
Networking, VOIP, Billing, NMS, Flash/Flex etc.

*Exp: 5+*
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] refactoring

2010-12-05 Thread steve
I had sent this reply below earlier ...not sure why it didn't go thru' 
...anyways, enough has already been said about this, however, since I already 
wrote this reply below, I thought I might as well make my point ...


Hi Santosh,

On 12/04/2010 05:36 PM, Santosh Rajan wrote:

My 2 cents on this subject. I think the problem of differing
viewpoints is mainly due to the fact that there are two kinds of
software development.

1) Software product development
2) Bespoke software development.

Let us look at software product development, and let us look at all
the top open source software development projects like linux, apache,
mozilla etc etc. I have not seen refactoring as described by the book
used by any of the open source software products. I would like to know
if any one can show me refactoring used in software product
development.



The very nature of Open Source Software development model is refactoring ! It 
isn't called that but that's what it is. Try to describe the process of FOSS 
development and then the way code is affected by refactoring and you would see 
the similarities. The only difference is in FOSS projects this is done by 
separate individuals in an unplanned manner -- the net effect from the /code's/ 
perspective though is that is being refactored. I'd go as far as saying that 
patches which refactor existing code in mature FOSS products are as at least the 
same in number as those that introduce new features.


cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] refactoring

2010-12-03 Thread steve

Hi,

Just a note in sideways, about my own experience and opinion on this topic ...

On 12/01/2010 04:33 PM, Kenneth Gonsalves wrote:

hi,

I know that this has cropped up in a parallel thread, but anyway I would
like a new thread on this. In a LUG list a ruby guy made a statement
that 'No self respecting developer could function without having read
the refactoring book'. How relevant is this to python? I do not see much
except years ago something called bicycle repair man - is that still
used? or is this whole thing buzz?


I've been fortunate enough to work with people who employ one or more of these 
'good programming', 'agile' methods to become efficient in the day-to-day 
'engineering practice' of programming (as opposed to talking about it like high 
nose evolved computer science or using it in a throw away manner for 1 project 
for the sake of curiosity / demonstration).


So, I have learned to understand, appreciate and use things like TDD, CI and 
perform refactoring without ever reading one book on these things. I am sure, 
I'll better understand them if I did read the books but at the end of the day 
unless you use these techniques in your regular day-to-day work without 
employing short-cuts when they become inconvenient, it really just is mental 
masturbation.


Coming to refactoring in particular, in the terms that Fowler defines it, I 
think it is just formalization of common sense that most good programmers(*) 
already are intuitively aware of. I would risk a guess that the person in this 
thread who asserted A self respecting developer will NOT need to refactor his 
code in the first place. is just as inexperienced in 'real world' projects as 
the original person who said No self respecting developer could function 
without having read the refactoring book -- either of these views are extremely 
sweeping generalizations about the practice of programming. They are typical of 
people who've not faced fast approaching deadlines, while dealing with large 
code bases with evolving requirements, eventually led by PHBs or clueless customers.


Most good engineering practices get thrown out of the window under pressure. The 
advantage of some of these techniques is to minimize the effect of this reality 
(for eg: using TDD and CI) and also make it easier get back on track once the 
pressure eases (for eg: using refactoring) -- real world experience speaking !


cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] What kind of applications can we develop with Python

2010-12-03 Thread steve

Hi,

On 12/01/2010 05:22 PM, sreedhar ambati wrote:

Hi

I am new to Python.
I am from PHP,Microsoft .net background.
Can you tell me the real power behind Python language?


The real power of python comes from it's simplicity. It is a easy to learn, easy 
to read and easy to program in language. It is great at providing powerful 
programming constructs in a beautifully simple manner.


While other languages might seem simpler, they won't offer the same power 
whereas those that might be powerful don't match python's simplicity.



What kind of applications we can develop?


All kinds of applications. Since it is a general purpose language with a rich 
standard library and also tons of freely available third party libraries.



Please quote some real time projects where industries are using Python



http://en.wikipedia.org/wiki/List_of_Python_software

you might recognize some of the names under 'Commercial uses' there ;-) and

http://wiki.python.org/moin/OrganizationsUsingPython

cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] regular expression for Indian landline numbers

2010-11-25 Thread steve

On 11/25/2010 04:10 PM, Kenneth Gonsalves wrote:

On Thu, 2010-11-25 at 15:56 +0530, Anand Balachandran Pillai wrote:

   r'(^0\d{2}[-\s]{1}[1-6]{1}\d{7})|(^0\d{3}[-\s]{1}[1-6]{1}\d{6})|(^0
   \d{4}[-\s]{1}[1-6]{1}\d{5})'
 

 It is doable, but you should really use pyparsing for this - this is
 UGLY !


I know - but everything I tried to make it look good did not work. And
the app in which I am plugging this into requires an re.


Certainly, you can beautify that using the verbose option. Here is my attempt. 
(Note, I use the beautiful (?(id/name)yes-pattern|no-pattern) syntax for the 
black magic :)


phone_re = re.compile(r
(^0 # all std-codes start with 0
(
(?Ptwodigit\d{2})   | # the std-code group
(?Pthreedigit\d{3}) | # either two, three or four digits
(?Pfourdigit\d{4})# following the 0
)
[-\s]   # space or -
[1-6]   # first digit of phone number
(
(?(twodigit)\d{7})   |  # 7 more phone digits for 3 digit stdcode
(?(threedigit)\d{6}) |  # 6 more phone digits for 4 digit stdcode
(?(fourdigit)\d{5}) # 5 more phone digits for 5 digit stdcode
)
)$, re.VERBOSE)


hth,
cheers,
- steve
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] regular expression for Indian landline numbers

2010-11-25 Thread steve

On 11/25/2010 06:45 PM, steve wrote:

On 11/25/2010 04:10 PM, Kenneth Gonsalves wrote:

 On Thu, 2010-11-25 at 15:56 +0530, Anand Balachandran Pillai wrote:

 r'(^0\d{2}[-\s]{1}[1-6]{1}\d{7})|(^0\d{3}[-\s]{1}[1-6]{1}\d{6})|(^0
 \d{4}[-\s]{1}[1-6]{1}\d{5})'
  

  It is doable, but you should really use pyparsing for this - this is
  UGLY !


 I know - but everything I tried to make it look good did not work. And
 the app in which I am plugging this into requires an re.


Certainly, you can beautify that using the verbose option. Here is my attempt.
(Note, I use the beautiful (?(id/name)yes-pattern|no-pattern) syntax for the
black magic :)



I had a bit of time this morning and didn't feel like starting work just yet, so 
to amuse myself I completed this. Here is the proper regex ...with tests !


http://pastebin.com/yjP5H0i2


Basically, almost the same thing as I posted yesterday but with named groups for 
std-code and phone number.


cheers,
- steve
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] [Announcement] Training on Extending Python using C

2010-11-24 Thread steve

On 11/24/2010 02:07 PM, Noufal Ibrahim wrote:

On Wed, Nov 24 2010, Venkatraman S wrote:


[...]


 True. I dont think sharing the slides is going to do any harm in any
 case; especially when the speaker is not known well; though its the
 speaker's discretion to share or not.

 Actually, i attend most of the sessions/conferences only when the talk
 agenda/slides are available in advance.


[...]

I haven't really decided. There's a mix of slides and notes. Some of it
will be online. I'm still undecided about how much.




Firstly, wish you the best with this !! Like KG mentioned, we could do with some 
more python programmers.


On the topic of slides/notes, IMHO, free (as in freedom) documents are good. My 
recommendation would be to make your slides/notes available (possibly for a fee) 
under a CC-BY-SA (and possibly NC) license. This might also help people who 
cannot/do not want to attend the training but would like to buy/download the 
courseware.


I understand completely the point about the time and effort it takes to create 
content (having conducted trainings myself) but that's a one time investment. 
Having free documents /might/ help you improve them via suggestions/patches from 
others.


just my opinion.

cheers,
- steve
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] [Announcement] Training on Extending Python using C

2010-11-24 Thread steve

On 11/24/2010 10:36 PM, Noufal Ibrahim wrote:

On Wed, Nov 24 2010, steve wrote:

[...]


 Firstly, wish you the best with this !! Like KG mentioned, we could do
 with some more python programmers.

 On the topic of slides/notes, IMHO, free (as in freedom) documents are
 good. My recommendation would be to make your slides/notes available
 (possibly for a fee) under a CC-BY-SA (and possibly NC) license. This
 might also help people who cannot/do not want to attend the training
 but would like to buy/download the courseware.

 I understand completely the point about the time and effort it takes
 to create content (having conducted trainings myself) but that's a one
 time investment. Having free documents /might/ help you improve them
 via suggestions/patches from others.


[...]

What I intended as a simple announcement has become a rather useful
thread on how to structure my material.

Thanks for the suggestions. :)



I remembered this only after I sent the mail, here is an example of what I was 
speaking of:


http://www.upfrontsystems.co.za/courses

I had used that to conduct one zope course myself (with explicit permission from 
the guys at Upfront). If you skim through the material you'll see that they make 
references to the handouts and code but that isn't available for download (but 
that does not make the content less useful).


cheers,
- steve
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] When *not* to use Python

2010-10-20 Thread steve

Hi,

On 10/20/2010 05:34 PM, Santosh Rajan wrote:

I have a slightly tangential take on this subject. I do web development and
it is entirely python nowadays. Having said that let me quote Eric Raymond.
*Lisp is worth learning for the profound enlightenment experience you will
have when you finally get it; that experience will make you a better
programmer for the rest of your days, even if you never actually use Lisp
itself a lot.*

I have learned and use Clojure a dialect of Lisp for some odd jobs just for
this reason.



I've had this on my todo list for sometime but then I read ..

http://sayspy.blogspot.com/2010/10/my-thoughts-on-clojure.html

...which made me re-think whether it was worth the effort (I already know a 
smattering of scheme but not well enough to consider it for anything resembling 
serious work).


Just curious, what do you (or anyone who has bothered learning clojure) think 
about that ?


cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] When *not* to use Python

2010-10-20 Thread steve

On 10/20/2010 04:57 PM, Noufal Ibrahim wrote:


The project management thread highlighted this issue of if it's not in
Python, I don't want to use it.

Assuming that most of the people here are mostly python enthusiasts or
learners, I'm wondering when you would *not* use Python. Let's not
conflate this with Open Source/Closed Source etc.

I'm just interested in situations where you'd stay away from something
*just* because it isn't in Python. The only reason I'd stay away from
something like this is if I needed to work on it's code and it was in a
language that I wasn't familiar with and didn't have the time to learn.

Also, there are plently of situations where I'd jump to a language other
than Python at the outset (e.g. for log file parsing, Perl still wins
for me).

Comments?


...for systems programming obviously, corepy[1] and pyasm[2] notwithstanding. :)

Seriously though, one aspect is small to medium sized automation/shell scripts 
where although sometimes one is tempted to use the 'power' of python, doing a 
`ls` instead of os.listdir('.') and `/some/random/command` instead of using the 
shutil/commands/subprocess ...etc modules is more pragmatic.


cheers,
- steve

[1] http://www.corepy.org/
[2] http://members.verizon.net/~olsongt/usersGuide.html

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] something in python similar to java applets

2010-09-07 Thread steve

Hello Naman,

On 09/06/2010 06:32 PM, naman jain wrote:

Hello,

I want to do something through python what applets do in java.
Through a website I want people to log in and do some tests locally on their
machines and send the results
to the server.

According to my understanding we have methods like applets or flash to do
something
locally on the client machine.

Is there any way in python we can achieve it ?


The only reason why Java applets or Flash can 'do something locally on the 
client machine' is because the browser 'allows' it do so use using plugins like 
a Java runtime or a flash player. Basically, browsers by themselves are 
incapable of executing any code(*). So, if you want to execute python code from 
a browser, your clients would will need a browser that supports python runtime, 
which afaik does not exist.


Most people use Javascript (which most people enable on their browsers these 
days) for basic client side execution or Java/Flash, which have client side, 
browser/runtime/OS specific quirks.



I have my test scripts in python(which do some communication and file
transfer to serial devices connected locally),  and I would like to avoid
rewriting them in java.



Judging by what you require, you'd be better off creating a standalone 
downloadable executable.


hth,
- steve

(*) HTML is not code and most (all?) browsers have a javascript engine to 
execute javascript code.


--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] how to delete base class attribute

2010-07-29 Thread steve

Hi Nitin,

On 07/29/2010 02:18 PM, Nitin Kumar wrote:

Hi all,



Say I have 10 functions in base class and I have inherited it in some
derived class.

But I only want 9 of the base class function to be available in child class.
(and I don’t want to make that one class private)




Python encourages clear design by not providing facilities to /enforce/ policies 
as part of the language. That's the reason why there are no 
public/protected/private keywords in python. There are only conventions to be 
followed. Here are some possible solutions:


a. Are you sure you got your class hierarchy right ? If one class needs all the 
methods of the other except one, the one with the most commonality should 
probably be the base class. In your case, it would be flipping the hierarchy on 
it' head.


b. If some method is 'special' to a class name it using leading and trailing 
'__' so that users deriving from the class know it is special.


c. This is now going into hacky territory -- if you decide to keep the same 
hierarchy as you have now, assign self.A in class 'y' to None[1] or explicitly 
implement it to raise an AttributeError[2]. The reason you cannot 'del' self.A 
is precisely because of what the error says AttributeError: y instance has no 
attribute 'A' -- A is just a 'bound' method to the object, not an attribute of 
the object and AFAICT there is no way to un-bind something off an object.



[1]

class y(x):
def __init__(self):
super(y, self).__init__() # btw, use super if possible
self.A = None

[2]
class y(x):
def __init__(self):
...
def A(self):
raise AttributeError(y instance has no attribute A)

hth,
cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] list problem

2010-07-22 Thread steve

On 07/22/2010 03:21 PM, Vikram wrote:

Suppose you have the following list:


 x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]]


My problem is that i wish to obtain the following two dictionaries:
xdictstart = {'cat':10, 'dog':1}
xdictend = {'cat':30, 'dog':5}

I don't get it, what's the criteria for creating xdictstart and xdictend ? Is 
start the lowest value of element 1 for each element 0 and xdictend the highest ?


If it is:

 x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]]
 d = {}
 for k, v in x:
... d.setdefault(k, []).append(v)
...
 d
{'dog': [5, 1, 3], 'cat': [10, 20, 30]}
 xstartdict = {}
 xenddict = {}
 for k, v in d.items():
... xstartdict[k] = min(v)
... xenddict[k] = max(v)
...
 xstartdict, xenddict
({'dog': 1, 'cat': 10}, {'dog': 5, 'cat': 30})


cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] catching exceptions from SimpleHTTPServer

2010-07-20 Thread steve

On 07/20/2010 11:45 PM, Rahul R wrote:

 negative aint working  , i tried a few changes myself . when i referred to
the class BaseHTTPServer s methods ( http://bit.ly/aYqnQE ) i found a
particular method log_message which is similar to sys.stderr but for some
reason it isnt appending ne data into the log file created.


Seems to be working for me:
http://codepad.org/MppnYU9n

I'm taking a wild guess here, you skimmed the docs and saw log_message() but 
didn't realize it is a method of the BaseHTTPRequestHandler class, *not* the 
HTTPServer class. Did I get that right ? can't blame you if I did, the docs are 
arranged in a such a manner that making this mistake is easy :).


cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] How to run *.py scripts which interfaces with modules

2010-07-14 Thread steve

Hi,

On 07/14/2010 07:43 PM,  स्वक्ष  wrote:

On Wed, Jul 14, 2010 at 18:04, Naresh Khalasinkhal...@vayana.in  wrote:

 Hi,

 The root directory (where your package starts) should be added to PYTHONPATH
 environment variable.
 e.g. if your root directory is /home/username/projects/mailman
 export PYTHONPATH=$PYTHONPATH:/home/username/projects/mailman


[...snip...]
This results in the ImportError (mentioned earlier).

Besides from Mailman import Mailbox in turn refers to email and its
path is: sys.path.append(/home/$user/mailman-2.1.10/misc/email-2.58/email/).

So if I set this path inside each of of these *.pyfiles,  using   ---
sys.path.append(/home/$user/mailman-2.1.10/Mailman/)  command,
etc...==  I'm able to test-run it. But without the path setting,
the program fails throwing errors.


That is what Naresh was trying to explain. If you want to set the path which the 
python interpreter would look at 'outside' the python modules, you can set the 
environment variable PYTHONPATH.


eg: instead of doing a sys.path.append('/home/$user/...') do a:

$ export PYTHONPATH=/home/$user/...:/some/other/path:...

...before executing your python script/application.

If you've ever used a Unix based system you'll recognize that the $PYTHONPATH 
variable is similar to the $PATH variable, in that the interpreter (sh or 
python) looks at this variable to find the command/script/module to execute/import.


There is another way to fix this issue -- the .pth file/site.py. More 
information about this issue at:


http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH

http://docs.python.org/library/site.html
http://bob.pythonmac.org/archives/2005/02/06/using-pth-files-for-python-development/

cheers,
- steve
--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] designing programs

2010-06-25 Thread steve

On 06/25/2010 11:04 AM, Kenneth Gonsalves wrote:

On Friday 25 June 2010 10:57:00 Elvis Joel D'Souza wrote:

   program
   has to do something one has to sketch out the data structures and
   functions that are needed to get the thing done with the least possible
   effort.

 I think you are referring to Design Patterns
 Head First Design Patterns can help...
 http://oreilly.com/catalog/9780596007126



I am not referring to Design Patterns - I think flow charting is the word I am
looking for


Like Noufal said, nothing beats pen and paper. What I usually do is:

a. Draw boxes -- Start from the most high-level components that you can identify 
and draw separate boxes for each one. Connect them up with lines to describe 
relationships. Then start with each individual box on a new piece of paper and 
break it down the same way.


b. Sometimes it helps to draw a mind map[1]. There are of course mind mapping 
software too. Google for those.


c. Once i reach a point where drawing boxes and maps doesn't make things any 
clearer and the only thing that will clarify it further is code, I make a 
skeletal file+class+methods -- if possible, I also write test cases (with the 
skeletal classes/functions returning dummy data so that tests pass).


d. I start coding :).

The problem with trying to create a complete and authoritative design using 
formal tools is, the design just gets obsolete almost as soon as you start 
coding, since updating the design to reflect changes introduced by reality (as 
opposed to abstract ideas, which is what one works with during design) is 
painful, nobody does it (at least not by the end when the product is almost ready).


Here is something I'll always remember because it changed my thoughts on the 
matter of design completely:

 http://www.developerdotstar.com/mag/articles/reeves_design_main.html

hth,
cheers,
- steve

[1] http://en.wikipedia.org/wiki/Mind_map
--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] UI Designing

2010-05-31 Thread steve

Hi,

Please, please, please ..do not top post !

On 05/31/2010 02:58 PM, Jeffrey Jose wrote:

For UI design, I

1. Start off with pen and paper, quickly mock up several designs and
interaction patterns
2. Proceed onto Photoshop/Illustrator to get a feel of how things would
look at the end.

Repeat 1 and 2 over and over

Once I'm ok with a design, I proceed to the next phase, probably writing
some code.



I stumbled upon this recently which might help with 1 and 2:
http://konigi.com/tools/graph-paper

cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] UI Designing

2010-05-31 Thread steve

Hi,

addendum ...

On 05/31/2010 03:23 PM, steve wrote:

Hi,

[...snip...]
I stumbled upon this recently which might help with 1 and 2:
http://konigi.com/tools/graph-paper



I am not a designer, but a quick google threw up this:

http://www.geekchix.org/blog/2010/01/03/a-collection-of-printable-sketch-templates-and-sketch-books-for-wireframing/

which might be interesting too !

cheers,
- steve
--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Python code documentation doubt

2010-04-22 Thread steve

On 04/22/2010 12:29 PM, JAGANADH G wrote:

Dear All

where can I find some guide/guidelines for code documentation like this


 single_record.pmid
 u'7024555'
 single_record +
- B{.title}
- B{.pmid}
- B{.Abs} I{(abstracts)}
- B{.year}

I am looking for a guide to learn the technique of writing such kind of code
document in my module.



From what you've posted, it looks more like the __repr__ of the 'pmid' object 
rather than code documentation. Here is a console session (pretty self 
explanatory) demonstrating the use of __repr__ ...and a bit more (ie: the 
difference between that and __str__ ) :


--
 class A:
... def __init__(self, x):
... self.x = x
...
... def __str__(self):
... return str(self.x)
...
... def __repr__(self):
... return I am a %s with the value %d % (self.__class__, self.x)
...
 a = A()
 a = A(10)
 a
I am a __main__.A with the value 10
 print a
10

--

If you need additional explanation or clarification, please ask.

hth,
cheers,
- steve
--
random new spiel: http://lonetwin.net/
random old spiel: http://lonetwin.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Python-Django developers required

2010-03-22 Thread steve

On 03/22/2010 06:09 PM, Anand Balachandran Pillai wrote:

On Mon, Mar 22, 2010 at 6:06 PM, Manish Singhman...@indiakhelo.com  wrote:


 Hi,

  http://mail.python.org/mailman/listinfo/bangpypers



Please prefix title of job postings with [Job].


Also, posting here might help too:
http://fossjobs.in
http://www.python.org/community/jobs/index.html

cheers,
- steve

--
random new spiel: http://lonetwin.net/
random old spiel: http://lonetwin.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Simple python database library

2010-03-05 Thread steve

On 03/05/2010 03:37 PM, Kenneth Gonsalves wrote:

On Friday 05 Mar 2010 3:22:12 pm Dhananjay Nene wrote:

   I might add that I've worked with ORMs almost regularly since 1996 in
   C++,

 Java and Python. SQLAlchemy has probably been the most successful ORM I
  have seen which has managed to retain the balance between relational and
  object paradigms (almost everyone else completely throws in the towel
  towards providing an object API around database access).



what about django's orm?


or SQLObject for that matter. I personally prefer SQLObject because it comes 
across as being more pythonic than SQLAlchemy, of course YMMV.


Dhananjay: I know you've already made up your mind on what to use but I just 
wanted to put this in sideways because it is so awesome (for some apps) -- the 
granddaddy of all db-object abstractions -- http://docs.zope.org/zodb/


Maybe not what you currently need but certainly something useful.

cheers,
- steve
--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Calling Python script from C++.

2010-02-26 Thread steve

Hi,

On 02/25/2010 07:32 PM, lakshmi.chow...@bt.com wrote:

Hi Zubin,

[...snip...]
In the function definition, I am taking 1 hard coded variable and needs
to pass this variable along with the string(python code) to
PyRun_SimpleString() and execute it.

Could you tell me the solution how to map the argument to the
string(python code) and pass to PyRun_SimpleString() and execute
successfully?



Is there any specific reason you choose to read the entire file and execute it 
using PyRun_SimpleString() as opposed to the more traditional and standard 
methods of using fork()+exec*() or system() functions ?


cheers,
- steve

--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] which one is the best pythonic way .

2010-02-08 Thread steve

On 02/09/2010 10:37 AM, Anand Chitipothu wrote:

On Tue, Feb 9, 2010 at 10:22 AM, Srinivas Reddy Thatiparthy
[...snip...]
#1.

You can even remove the square brackets.

sum(i for i in range(1000) if i%3==0 or i%5==0)


Yes, you can but that doesn't necessarily mean it is better. Interestingly, 
something similar was discussed at comp.lang.python:


http://groups.google.com/group/comp.lang.python/browse_thread/thread/7897bf3fd2298332/26247987f84cc484


cheers,
- steve
--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] using IPython from pdb

2010-02-07 Thread steve

Hi Shashwat,

On 02/06/2010 11:20 PM, Shashwat Anand wrote:

here is the bpython screencast : http://*bpython*-interpreter.org/static/*
bpython*-screencast01.
ogg
It's worth trying.


+1. (Having tried both ipython and bpython, I prefer bpython mainly because of 
the cleaner interface (ie: no unnecessary whitespace/newlines) and the ability 
to show the doc strings as you type).



By the way does anyone want to share their customized Vi features with
respect to python. I am pretty much satisfied with my own but there is
always scope for improvements.

I assume you meant vim. If that assumption is correct, there isn't much python 
specific that I do except for adding...


autocmd BufNewFile,BufRead *.py let python_highlight_all = 1

...to my ~/.vimrc. Read the comments at the top of vim's python syntax file 
(typically /usr/share/vim/vimversion/syntax/python.vim on linux) to understand 
what that means.


However, non-python specific, I like the following vim scripts for coding:

taglist.vim [ http://www.vim.org/scripts/script.php?script_id=273 ]
supertab.vim [ http://www.vim.org/scripts/script.php?script_id=1643 ]
vcscommand.vim [ http://www.vim.org/scripts/script.php?script_id=90 ]
NERD_tree.vim [ http://www.vim.org/scripts/script.php?script_id=1658 ]

cheers,
- steve
--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Internationals getting Python/Programming Jobs

2010-02-06 Thread steve

Hi Rory,

On 02/05/2010 04:16 PM, Rory Hart wrote:

Hi all,

I'm an Australian who is considering living/working in Bangalore, I work
with a lot of Indians here in Australia and figure why should they have all
the fun of coming to another country to work.

Makes sense. In my previous jobs, a lot of international colleagues who came for 
short business visits, noted that India isn't all that bad as a place to stay, 
work and grow professionally for a few years (despite things that people from 
developed nations take for granted ie: good roads, regular water and electricity 
and overall predictability and reliability of general infrastructure).


This sort of thing is best done in the early years of your career.


The main questions I have are:

- Do Bangalore IT companies hire many internationals?
Well, as others noted, getting a work visa might be tough. Not due to any 
underling protectionist agenda but due to the sheer chaotic and utterly 
frustrating bureaucratic machinery. That said, if you do manage to get one (or 
convince an Indian company to get one for you), you'll find the job market 
pretty good. Most 'good' companies won't really care if you are an 
international. More about the 'good' part later.



- Can you get by with English only? (I note with happiness all
the correspondence on this list appears to be in English)


Absolutely ! I'd say 98% of software business gets done in English here in 
India. The accent though might be a problem initially (not only yours but the 
varied ones that we have here :) ).



- What are the Python job prospects like in Bangalore?


Umm, widen your choice beyond Bangalore. Consider places like Pune, Delhi 
(including NCR) and Hyderabad.


Python job prospects in India are mainly web application development related. 
Although there are a few companies that do use python for non-web application 
development. I don't think there are any stats available though.



- Do any of you work with/are internationals working in Bangalore and
would be willing to talk to me about it in more depth?

In an earlier job I worked with a French guy who decided to take up a job in 
India to help him stay, travel and experience India. He managed to pull it off 
for 4+ years (i think). I'll put you in touch with him.



Any other insights people have would be much appreciated, for example: am I
mad?

Not really. The work part makes sense, the only possibly mad bit is thinking 
that you can survive India, without ever visiting this beautifully dualistic(*) 
county. Nothing can prepare you for the cultural and social shock that you get 
when you first visit. How you'll handle it will tell whether you were mad or not.


Now, about the good company part -- note that most big software firms in India 
are code monkey farms, with production line engineers, ejected into our industry 
by the don't-think-just-cram education system of our country. So, if you are 
unfortunate enough to land up in one of those, you'll become frustrated very 
quickly. I think this explains the work culture of the majority of Indian 
software firms:


http://sivers.org/book/SpeakingOfIndia

So, choose wisely. Rule of thumb -- In India, working at a product development 
companies is better than working at service oriented companies (yes, that might 
be a flame bait, but what the heck, that's my personal experience).


cheers,
- steve

(*) Whatever you can rightly say about India, the opposite is also true.
   - Joan Robinson
--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] using IPython from pdb

2010-02-03 Thread steve

On 02/04/2010 05:43 AM, Senthil Kumaran wrote:

Using IPython from pdb, what use is it?
I read Jeff's excellent mail on debugging and tracing and he insisted on
using IPython from pdb. I have used pdb extensively and never used IPython,
(it never caught me, given that odd interface of number[:]) etc.

I don't know anything about the problem you mention (or the mail you refer to) 
but I agree with the comment about the odd interface of ipython. In case you are 
on linux and are looking for a more powerful CLI than the standard python 
interface, I would recommend trying out bpython:


http://bpython-interpreter.org/
http://bpython-interpreter.org/screenshots/

cheers,
- steve

--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Hi.......

2010-01-13 Thread steve

Hi,

On 01/13/2010 02:15 PM, Smrutilekha Swain wrote:

i am doing a programme in which i have to copy a file from one directory to
anotheri have used shutil.copy(src,dest)...but it is showing error
i.e., permission denied...as file is in 'w' mode...so plzz tell me what
to do.


Are you sure the permission denied is because the file is opened in 'w' mode ?

 l = open('foo', 'w')
 shutil.copy('bar', 'foo')


It is quite likely that you do not have sufficient privileges to write to the 
target directory. For instance ...


 shutil.copy('foo', '/')
Traceback (most recent call last):
  File input, line 1, in module
  File /usr/lib64/python2.6/shutil.py, line 88, in copy
copyfile(src, dst)
  File /usr/lib64/python2.6/shutil.py, line 53, in copyfile
fdst = open(dst, 'wb')
IOError: [Errno 13] Permission denied: '/foo'


Make sure that normal copy (using the cp command on the shell/command prompt) 
works before trying out shutil.copy. If that works but shutil.copy() doesn't, 
could you place the entire traceback here ?


cheers,
- steve
--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Python and USB

2010-01-13 Thread steve

On 01/13/2010 03:01 PM, Anand Balachandran Pillai wrote:

On Wed, Jan 13, 2010 at 2:56 PM, Vishalvsapr...@gmail.com  wrote:


 Hi,

 I am looking for a way to create a python library that talks to some usb
 devices (such as usb-i2c cards etc). There is a requirement that the python
 library should be usable directly under windows and linux withough
 requiring
 the user to worry about her platform.

 Any pointers?

 I did find a couple, PyUsb on sourceforge, and another PyUSB that deals
 only
 with FTDI USB devices...

 Has anybody used these?



  No, doesn't pyserial work ? Anyway USB is a serial bus...


heh, yeah, USB is a serial bus just like ethernet is serial communication.

cheers,
- steve

--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] meta programming

2009-11-30 Thread steve

On 11/26/2009 05:06 PM, mahaboob_sub...@dellteam.com wrote:

Hi All,



Is there any good python Meta programming tutorial?



http://www.ibm.com/developerworks/linux/library/l-pymeta.html

In fact, I recommend all of David Mertz's, 'Charming Python' articles

http://gnosis.cx/publish/tech_index_cp.html

(note: the icons are links to html versions of the plain text article links)

cheers,
- steve
--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Google Go

2009-11-11 Thread steve

On 11/11/2009 04:17 PM, Ramdas S wrote:



 But I don't see the Python connection at all here.



Yeah! I jumped the line without reading. Actually going through now and
downloading the stuff I cant see much  from Python perspective, that bloody
language is full of braces, but yes syntactically its more sugary and clean

seriously ?? no, really, are you serious ? you got more sugary from 
Titlecase.Method.Names ? (Printf now requires a damn shift key !! what was ken 
thompson thinking ??).


That was my first reaction.

Well, other than that, I think it is pretty nice language ...but doesn't really 
/stand out/ for anything in particular (like python's simplicity and beauty did, 
when I first made its acquaintance). Then again I am not a  polyglot as far as 
programming is concerned ...so I might not be able to appreciate it's value 
...yet ...


cheers,
- steve


--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] 2-cent Tip: Load modules at Startup

2009-10-23 Thread steve

On 10/22/2009 07:41 PM, Noufal Ibrahim wrote:

On Thu, Oct 22, 2009 at 6:43 PM, Amit Sahalists.amits...@gmail.com  wrote:

 Hello:

 I have been using CPython as a calculator, while I do all those number
 crunching in C. SO, 'import math' is a must.

 This is what I did:

 - Create a file: .pythonrc in my $HOME and place this line:


There are other goodies you can put there as well. I used to have

import readline
readline.parse_and_bind(tab: complete)

in there so that the default interpreter would get tab completion.


I also have this is my .pythonrc:

import os
import readline
histfile = os.path.join(os.environ[HOME], .pyhist)
try:
readline.read_history_file(histfile)
except IOError:
pass
import atexit
atexit.register(readline.write_history_file, histfile)
del os, histfile

This lets you save the history of every thing you type in your interpreter 
session much like the bash history functionality. This is immensely useful when 
I am trying out stuff on the prompt before creating a script.


Of course all this also comes built-in with the Ipython environment, but I never 
really got hooked on to that.


Anyways, besides the tip, I'd also like to point out to the 'atexit' module 
which the above tip uses. It is included in the stdlib and can prove to be quite 
useful at times. That one is good to know about.


cheers,
- steve
--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] 2-cent Tip: Load modules at Startup

2009-10-23 Thread steve

On 10/23/2009 12:48 PM, Noufal Ibrahim wrote:

On Fri, Oct 23, 2009 at 12:41 PM, stevest...@lonetwin.net  wrote:
[..]

 Of course all this also comes built-in with the Ipython environment, but I
 never really got hooked on to that.

[..]

Do you have any reasons why? It's praised a lot in some circles but I
got a lot of negative comments about it on the #python channel.


Well, for me, there aren't any strong negative reasons really. I just felt that 
the interface was a bit 'clunky' (the extraneous use of spaces and newlines 
makes me nervous), the commands/shortcuts were non-intuitive to me and I just 
don't like reading docs before trying out something -- which I think is required 
for using ipython.


However, i still do recommend it to people who want colors, completion and all 
sorts of customization abilities from their prompt.


cheers,
- steve
--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] I am new to python language. Suggest way to improve my skills in python

2009-10-20 Thread steve

On 10/20/2009 11:34 AM, Senthil Kumar M wrote:

I am new to python language. Suggest way to improve my skills in python

read python code
write python code
fight pythons in the wild

I am sure two of those three were obvious to you so asking such a general 
question did help, didn't it ?


cheers,
- steve

--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] Place the timer in Python script

2009-09-18 Thread steve

On 09/18/2009 03:33 PM, Vamsi wrote:

How to place the timer in python code.

I want calculate the python script execution time.

ex : Start Timer
  : End Timer

Execution Time : End Timer - Start Timer.

How can we write the python code for this.

http://docs.python.org/library/debug.html

Specifically, the timeit module
http://docs.python.org/library/timeit.html

btw, dunno if you've heard about this really neat web application. It is a 
simple text box with a couple of buttons that answers questions such as these. I 
forgot it's name. It's something like golgol or some such.


cheers,
- steve

--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] suppressing the exception stack trace

2009-09-16 Thread steve

On 09/16/2009 11:39 AM, Vishal wrote:



On Tue, Sep 15, 2009 at 9:07 PM, steve st...@lonetwin.net
mailto:st...@lonetwin.net wrote:

On 09/15/2009 08:56 PM, Vishal wrote:

Hello,

I would like to raise an exception of type Exception(), however the
regular exception stack trace needs to be supressed.

This is needed in a function that takes raw_input() from the
user and
based on 'Y' or 'N', the function suspends further execution and
returns
to the python prompt or Hicontinues. An exit() brings it out of
the python
processwhere as what is needed is coming back to the python
prompt.

I want a custom message to appear instead of a regular exception
stack
trace message.

How to do this? any pointers...?

Python 2.6 (r26:66714, Jun  8 2009, 16:07:29)
[GCC 4.4.0 20090506 (Red Hat 4.4.0-4)] on linux2
Type help, copyright, credits or license for more information.
  import traceback
  try:
... 1 + foo
... except Exception, e:
... traceback.format_stack(limit=1)
...
['  File stdin, line 4, in module\n']
  help(traceback)


HTH,
- steve



Forgot to mention that we are currently stuck with python2.5.2

As part of a debug/test hook, I would like to suspend further action of
a program, after a certain point in the procedure. What I had come up
with is a function named testHook() which does this:

def testHook():


 choice = raw_input(Would you like to continue (Y or N): )
 try:
 if(str(choice).lower() != 'y'):
 print(You chose not to go ahead. Ok!!\nAborting Now...)
 raise Exception(User initiated Abort...)
 except Exception:
 raise # re-raise it..so we come out of execution loop

In this case, a stack trace gets printed out, before the string 'user
initiated abort' comes up. I want to remove that stack trace...so it
looks more clean to a user.

What can be done in this case?


Well, I don't understand how and from what context you are calling testHook(). 
My first instinct is to ask, why you can't simply return instead of 'raise' on 
an abort ? like so ...


def testHook(exc):
choice = raw_input(Would you like to continue (Y or N): )
if(str(choice).lower() != 'y'):
print(You chose not to go ahead. Ok!!\nAborting Now...)
print User initiated Abort...
return -1 # ...or any other value that makes sense to your app.
else:
raise exc # re-raise the passed exception

In which case, I am assuming testHook() called like this:
try:
1 + foo
except Exception, e:
return testHook(e)


or any other way of creating such a hook?

Yes. The way I would do this sort of this is by using decorators:

 def testHook(func):
... def wrap_exception(*args):
... try:
... func(*args)
... except Exception, e:
... choice = raw_input(Would you like to continue (Y or N): 
)
... if (str(choice).lower() != 'y'):
... print(You chose not to go ahead. Ok!!\nAborting 
Now...)

... print User initiated abort ...
... print on recieving %s % e.message
... return
... else:
... print redirect to debugger in this block ...
... return wrap_exception
...
 @testHook
... def main(a, b):
... return a + b
...
 main(1, foo)
Would you like to continue (Y or N): n
You chose not to go ahead. Ok!!
Aborting Now...
User initiated abort ...
on recieving unsupported operand type(s) for +: 'int' and 'str'



Here is a good article for introducing decorators:
http://www.ibm.com/developerworks/linux/library/l-cpdecor.html

HTH,
cheers,
- steve
--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] [OT] Guido's Tweet on Top Posting

2009-09-11 Thread steve

On 09/11/2009 01:24 PM, Kenneth Gonsalves wrote:

On Friday 11 Sep 2009 11:00:41 am Kenneth Gonsalves wrote:

 On Friday 11 Sep 2009 10:54:27 am srid wrote:
From Wikipedia:
 
   
   Objections to top-posting on newsgroups, as a rule, seem to come from
   persons who first went online in the earlier days of Usenet, and in
   communities that date to Usenet's early days. Until the mid-90s,
   top-posting was unknown and interleaved posting an obvious standard
   that all net.newcomers had to learn. Among the most vehement
   communities are those in the Usenet comp.lang hierarchy, especially
   comp.lang.c and comp.lang.c++. Top-posting is more tolerated on the
   alt hierarchy. Newer online participants, especially those with
   limited experience of Usenet, tend to be less sensitive to arguments
   about posting style.
   

 BS


why? in the first place I am extremely sensitive to top posting, but have never
used usenet or been in a C forum. I only learned about interleaved posting in
[...snip...]
Therefore 'Newer online participants, especially those with
  limited experience of Usenet, tend to be less sensitive to arguments about
posting style.' is sheer BS. The majority of people online are just as
sensitive to arguments about good manners as the old timers. The only thing is
that they are ignorant.
[...snip...]
btw, I am not talking of the general non-IT mailing lists.


Just to be a pedant, I should point out that the quoted paragraph clearly states 
that Objections to top-posting on /newsgroups/...


The entire paragraph is in the context of newsgroups (and Usenet in particular).

Also, about the original tweet --  That is possibly just an off hand remark 
(directed at one particular person) by a guy, just the fact that the guy is gvr 
and is saying something unexpected when taken out of context is not reason 
enough to post it to a python mailing list, IMHO. Doing that is plain stupid but 
unfortunately it happens all the time with twitter. This is exactly what I hate 
about twitter -- there is no context.


cheers,
- steve

--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers


Re: [BangPypers] link

2009-09-03 Thread steve

On 09/03/2009 10:46 PM, Noufal Ibrahim wrote:

On Thu, Sep 3, 2009 at 10:43 PM, bhaskar jainbhaskar.jain2...@gmail.com  
wrote:

 Nice link -  http://aymanh.com/python-debugging-techniques
 We can have this thread were we discuss our own debugging techniques.
 I uses syslog :(
 and kind of like 'inspect' and 'traceback' modules.



* Debugging: Guido uses print statements for 90% of his debugging and
a debugger for the times when his brain stops working or he has to
debug some wierd code that someone else wrote.

Of course the primary difference, IMHO is most python programmers are debugging 
application/modules written in python whereas Gudio debugs the language itself 
and the standard library. I wonder how many regular python users ever need to 
put a print statement in any of python's standard modules (I've done it a couple 
of times, just because the docs seemed too obscure/complicated/vague to be 
bothered with and it was faster for me just to use print).


Anyways, regarding the question, I find that most python programmers I've met 
either use print (and other variations like traceback.print_*) or a custom coded 
logging/debuging module.


Recently, i've come across these two which might be useful, but I haven't had a 
reason to try them out yet:

http://wordaligned.org/svn/etc/echo/echo.py
http://codeinvestigator.googlepages.com/main

...and lastly, I've used pdb occasionally (actually, the most frequent use was 
when being dropped in the built in pdb prompt when anaconda (the Red Hat/fedora 
installer) barfs) and even then, I didn't really find it all that useful from a 
'debugging' perspective. It works well only to examine state.


cheers,
- steve

--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers