packaging a python application

2011-08-27 Thread suresh
Hi
I created a python application which consists of multiple python files and a 
configuration file. I am not sure, how can I distribute it. 

I read distutils2 documentation and a few blogs on python packaging. But I 
still have the following questions.

1. My package has a configuration file which has to be edited by the user. How 
do we achieve that? 

2. Should the user directly edit the configuration file, or there would be an 
interface for doing it...?(I remember my sendmail installations in 
Debian/Ubuntu. It would ask a bunch of questions and the cfg file would be 
ready)

I am just confused how to go about...

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


changing current dir and executing a shell script

2011-05-27 Thread suresh
Hi,
I want to execute the following command line stuff from inside python. 
$cd directory
$./executable

I tried the following but I get errors
import subprocess
subprocess.check_call('cd dir_name;./executable')

Due to filename path issues, I cannot try this version.
subprocess.check_call('./dir_name/executable')

Any suggestions?
thanks
suresh
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: changing current dir and executing a shell script

2011-05-27 Thread suresh
On Friday, May 27, 2011 3:19:22 PM UTC-7, Albert Hopkins wrote:
> On Fri, 2011-05-27 at 14:25 -0700, suresh wrote:
> > Hi,
> > I want to execute the following command line stuff from inside python. 
> > $cd directory
> > $./executable
> > 
> > I tried the following but I get errors
> > import subprocess
> > subprocess.check_call('cd dir_name;./executable')
> > 
> > Due to filename path issues, I cannot try this version.
> > subprocess.check_call('./dir_name/executable')
> > 
> 
> You don't want to do this because "cd" is a built-in shell command, and
> subprocess does not execute within a shell (by default).
> 
> The proper way to do this is to use the "cwd" keyword argument to
> subprocess calls, i.e.:
> 
> >>> subprocess.check_call(('/path/to/exec',), cwd="/path/to/dir")
> 
> -a

It works. thank you very much. I have been struggling with this for a very 
long time. 
suresh
-- 
http://mail.python.org/mailman/listinfo/python-list


sexe day

2008-06-16 Thread suresh
u want the all sexye flimes ues this

   u want me see  this ***
***
   http;//lesbiangroupsexy.blogspot.com/
--
http://mail.python.org/mailman/listinfo/python-list


SAP MM Cupertino, CA

2012-09-10 Thread Suresh Kumar
Hi,

This is Girish, - IT Recruiter  from SancroSoft USA Inc.

Please respond with updated resume in MS-Word .doc Format with the
following details to  [email protected]

Full Name :
Location :
Contact Number :
Email :
Availability :
Visa Status :

SAP MM
Location : Cupertino, CA
Duration:  3+ Months

Job Description:

• Candidate should possess excellent functional knowledge in SAP MM
for about 4-5 yrs and have 2 years of implementation or Production
support experience
• Should be strong in Procure to pay cycle covering the critical
aspects of Purchasing, Inventory Management & Invoice Verification.
• Should be able to understand the client business process so as to
map the requirements in SAP using standard solution methodology.
• Should be able to conduct Business workshops to drive the project
implementation using SAP standard implementation methodologies.
• Should be strong in Special processes which include Consignment
process, Subcontracting process & Batch Management.
• Should be comfortable in handling and preparation of Functional
Specifications and to work with developer to achieve RICEF objects.
• Should have cross functional expertise and should be strong in
integrating the system with other modules which includes SD, WM & FI.
• Should have worked and exposed to EDI Integration techniques along
with Idoc monitoring process.
• Should be an excellent team player & good team builder.
• Should demonstrate excellent communication skills.



 Thanks & Regards,

 Girish
 IT Recruiter.


 The power of focus
SancroSoft USA INC
4944 Sunrise Blvd, Suite B-4 || Fair Oaks, CA 95628
Phone : 916-671-5584|| Fax: 916-200-0305
E-Mail : [email protected]|| www.sancrosoftusa.com

Stay Connected:

The information contained in this email message is intended only for
the personal and confidential use of the recipient(s) named above. The
message may be privileged and confidential and protected from
disclosure. If the reader of this message is not the intended
recipient or an agent responsible for delivering it to the intended
recipient, you are hereby notified that you have received this
document in error and that any review, dissemination, distribution,
copying of this message is strictly prohibited. If you have received
this communication in error, please notify us immediately by email and
delete the original message.


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


What are the minimum requirements to get a job in?

2012-12-13 Thread suresh . pinnapa
My aim is to get a job into google or cisco or facebok.
I have basic knowledge in python,c,java and good in javascript,html,css, 
database concepts.
If i learn django and python. Shall I get my dream job?

Please suggest me
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Issues in python 3.11.0 (64-bit) installation

2022-11-03 Thread Suresh Babu
-- Forwarded message -
From: Suresh Babu 
Date: Thu, 3 Nov 2022, 16:37
Subject: Issues in python 3.11.0 (64-bit) installation
To: 


Sir/ Madam,
I downloaded the latest version of python i.e. python 3.11.0 ( 64-bit)
in my laptop recently. But the " py launcher " and " available for all
users " option is not working in the customization menu of python 3.11.0 .
Kindly help me in solving this issue.

My operating system is Windows 11. Kindly guide me in this regard.

Yours sincerely,

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


Unable to install folium using python version 3.8.4.

2020-09-15 Thread Suresh Unnikrishnan
Team,

I use python version 3.8.4.
I tried to import folium using IDLE but it was unsuccessful as it throws
errors. After that, I tried to use pip install folium in the command prompt
but it also throws an error. Kindly advise the steps to install folium.

Regards,
U.Suresh.
-- 
https://mail.python.org/mailman/listinfo/python-list


PIL

2005-03-30 Thread suresh mathi
I use PIL for image manipulation.
For drawing rectangles and other shapes PIL was really
good.

Now i am trying to paste 3 images into a single image.

All 3 images that i try to paste are having a
transparent background.
When i try to open the image and paste the background
becomes black. I masked the black areas but still the
shape is not that clear.

Is their any way to open the file in transparent mode
or convert it into transparent mode.?

Can any one help?



SURESH M.


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No matter what I do, IDLE will not work...

2011-11-11 Thread Suresh Sharma
Hello all,
I need to know how to connect python 3.2 with mysql db i am newbie and 
appreciate your help to enhance my skills.

I googled a lot but nothing came up 

Ned Deily  wrote:

>In article 
><[email protected]>,
> CAMERON ALLEY  wrote:
>> IT WORKS I didn't change my activestate, but I downloaded python
>> 3.2.2 with the 32 bit installer and it works! Perfectally!!
>> 
>> Sir you're my savior, thank you so much.
>> 
>> I don't know how you did it but you just made my day :)
>
>The 32-bit-installer links to the older Carbon-based Tcl/Tk 8.4 which is 
>very different under the covers from the Tcl/Tk 8.5 used by the 
>Apple-supplied Pythons and the python.org 64-bit installer.  So there's 
>*something* on your system that interferes with the Cocoa Tcl/Tk 8.5.  
>If you want to pursue it, you might ask on the OS X Tcl mailing list.  
>Good luck!
>
>http://dir.gmane.org/gmane.comp.lang.tcl.mac
>
>-- 
> Ned Deily,
> [email protected]
>
>-- 
>http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


class print method...

2011-12-04 Thread Suresh Sharma
Hello All,
I am new to python and i have stuck up on a particular issue with classes,
i understand this might be a very dumb question but please help me out.

I have created two classes and whenever i try to print the objects i get
this message but not the data,  __main__.cards instance at (memory
location) i even tried using __str__ but calling it also produces the same
result. Can anyone please help me how to get my objects printed. I googled
a lot but could not find anything relevant.

thanks in advance

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


Fwd: class print method...

2011-12-05 Thread Suresh Sharma
Pls help its really frustrating
-- Forwarded message --
From: Suresh Sharma
Date: Monday, December 5, 2011
Subject: class print method...
To: "[email protected]" 


Dave,
Thanx for the quick response, i am sorry that i did not explain correctly
look at the code below inspite of this i am just getting class object at
memory location.I am sort i typed all this code on my android in a hurry
so.indentation could.not.be.managed but this.similar code when i run all my
objects created by class deck are not shown but stored in varioia meory
locations. How can i display them.

Please help




Suit=[aces,clubs,diamonds,hearts]
Rank=[2,3,4,5,6,7,8,9,j,Q,K,A]
class Card:
Def __init__(self,rannk,suiit):
Self.suiit=suiit
Self.rannk=rannk

Def __str__(self):
Return suit[suiit],rank[rannk]

Class deck:
Def __init__(cards):
Self.cards=[ ]
For suit in range(4):
For rank in range(13):
Self.cards.append(Card(suit,rank))

Def __str__(self):
s = ""
For card in self.cards:
S = str(self.cards)
Return s.






On Monday, December 5, 2011, Dave Angel  wrote:
> On 12/05/2011 02:11 AM, Suresh Sharma wrote:
>>
>> Hello All,
>> I am new to python and i have stuck up on a particular issue with
classes,
>> i understand this might be a very dumb question but please help me out.
>>
>> I have created two classes and whenever i try to print the objects i get
>> this message but not the data,  __main__.cards instance at (memory
>> location) i even tried using __str__ but calling it also produces the
same
>> result. Can anyone please help me how to get my objects printed. I
googled
>> a lot but could not find anything relevant.
>>
>> thanks in advance
>>
>> regards
>> suresh
>>
> You were close, but you have it backward.  You don't call __str__() to
print an object, you implement __str__() in your object.
>
> If you write a class without also writing __str__(), then print won't
know what to do with it.
>
> --
>
> DaveA
>
>

--
Suresh Sharma
Regional Project Manager,
O2F,Mumbai
Maharashtra-400101.






-- 
Suresh Sharma
Regional Project Manager,
O2F,Mumbai
Maharashtra-400101.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fwd: class print method...

2011-12-05 Thread Suresh Sharma
Dave / Ryan
Thanks i have got it and it worked after using repr statement. Thanks
everyone for their valuable feedback.



On Mon, Dec 5, 2011 at 6:11 PM, Lie Ryan  wrote:

> On 12/05/2011 10:18 PM, Suresh Sharma wrote:
>
>>
>> Pls help its really frustrating
>> -- Forwarded message --
>> From: Suresh Sharma
>> Date: Monday, December 5, 2011
>> Subject: class print method...
>> To: "[email protected] <mailto:[email protected]>" > <mailto:[email protected]>>
>>
>>
>> Dave,
>> Thanx for the quick response, i am sorry that i did not explain
>> correctly look at the code below inspite of this i am just getting class
>> object at memory location.I am sort i typed all this code on my android
>> in a hurry so.indentation could.not.be.managed but this.similar code
>> when i run all my objects created by class deck are not shown but stored
>> in varioia meory locations. How can i display them.
>>
>>
> I think you're in the right track, however I suspect you're running the
> code in the shell instead of as a script. The shell uses __repr__() to
> print objects instead of __str__(), so you either need to use 'print' or
> you need to call str(), note the following:
>
> Python 2.7.2+ (default, Oct  4 2011, 20:06:09)
> [GCC 4.6.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> suits = ['spades', 'clubs', 'diamonds', 'hearts']
> >>> ranks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q',
> 'K']
> >>> class Card:
> ... def __init__(self, rank, suit):
> ... self.suit = suit
> ... self.rank = rank
> ... def __str__(self):
> ... return suits[self.suit] + ' ' + ranks[self.rank]
> ...
> >>> Card(2, 3) #1
> <__main__.Card instance at 0x7f719c3a20e0>
> >>> str(Card(2, 3)) #2 of your
> 'hearts 3'
> >>> print Card(2, 3) #3
> hearts 3
>
> In #1, the output is the __repr__() of your Card class; you can modify
> this output by overriding the __repr__() on your Card class.
>
> In #2, the output is the __repr__() of a string, the string is the return
> value from __str__() of your Card class. The repr of a string is the string
> enclosed in quotes, which is why there is an extra pair of quotes.
>
> In #3, you're 'print'-ing a string, the string is the return value from
> __str__() of your Card class. There's no extra quotes, since 'print' prints
> the string itself, not the repr of the string.
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>



-- 
Suresh Sharma
Regional Project Manager,
O2F,Mumbai
Maharashtra-400101.
-- 
http://mail.python.org/mailman/listinfo/python-list


openings on java with japanese language

2005-12-14 Thread suresh . reddy
send your profile to [EMAIL PROTECTED]

Job Code: JJ1

Job Description:

 Skills: Experience in Java, J2EE, Struts and servlets.

 This is for onsite (Japan) and should be proficient at
Japanese Knowledge (Level 3/4).

Number of positions : 6


Experience:

3-5 years on Real time experience on Struts and servlets.

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


parsing engineering symbols

2005-12-20 Thread Suresh Jeevanandam
Hi,
I want to convert a string to float value. The string contains 
engineering symbols.
For example,

s = '12k'

I want some function which would return 12000
function(s)
=> 12000.0
I searched the web, but could not find any function.

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


checking if a string contains a number

2005-12-20 Thread Suresh Jeevanandam
Hi,
I have a string like,
s1 = '12e3'
s2 = 'junk'

Now before converting these values to float, I want to check if they 
are valid numbers.

s1.isdigit returns False.

Is there any other function which would return True for s1 and False 
for s2.

Thanks

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


numarray :: multiplying all the elements in 1d array

2005-12-20 Thread Suresh Jeevanandam
Hi all,
Lets say I have an array:
from numarray import *
a = array([ 6,  7,  8,  9, 10, 11, 12])

I want to multiply out all the elements and get the result.

r = 1.0
for i in a:
r = r*i

Is there any faster, efficient way of doing this.

Thanks,

regards,
Suresh

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


Re: parsing engineering symbols

2005-12-21 Thread Suresh Jeevanandam

Exactly what I wanted.

It would be nice if the standard float function takes care of these.

regards,
Suresh

> how about:
> 
> SI_prefixes = {
> 'Y':24, 'Z':21, 'E':18, 'P':15, 'T':12, 'G':9, 'M':6, 'k':3,
> 'h':2, 'd':-1, 'c':-2, 'm':-3, u'\xb5':-6, 'u':-6, 'n':-9, 'p':-12,
> 'f':-15, 'a':-18, 'z':-21, 'y':-24
> }
> 
> def myfloat(str):
> try:
> exp = SI_prefixes[str[-1]]
> return float(str[:-1]) * 10**exp
> except KeyError:
> return float(str)
> 
> ?
> 
> 
> 
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Finding the relative path of a file from a dir

2006-01-20 Thread Suresh Jeevanandam
Hi,
a = '/home/suresh/doc/html/a1/'
b = '/home/suresh/doc/'

I am looking for a standard function which will return the location of b 
relative to a i.e. '../..'

I have gone through the os and os.path modules, but could not find any 
function of use. Should I write my own?

Thanks in advance,
Suresh
-- 
http://mail.python.org/mailman/listinfo/python-list


finding the intersection of a list of Sets

2006-01-31 Thread Suresh Jeevanandam
I have a list of sets in variable lsets .

Now I want to find the intersection of all the sets.

r = lsets[0]
for s in r[0:]:
r = r & s

Is there any other shorter way?

Thanks in advance,
Suresh
-- 
http://mail.python.org/mailman/listinfo/python-list


mapping functions and lambda

2006-02-15 Thread Suresh Jeevanandam
Given a string
s = 'a=1,b=2'

I want to create a dictionary {'a': '1', 'b': '2'}

I did,

dict(map(lambda k: k.split('='), s.split(',')))

Is it possible to get rid of the lambda here, without having to define 
another function just for this.

Is this the easiest/straight-forward way to do this?

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


Re: mapping functions and lambda

2006-02-15 Thread Suresh Jeevanandam
I got it:
dict([k.split('=') for k in s.split(',')])

regards,
Suresh
Suresh Jeevanandam wrote:
> Given a string
> s = 'a=1,b=2'
> 
> I want to create a dictionary {'a': '1', 'b': '2'}
> 
> I did,
> 
> dict(map(lambda k: k.split('='), s.split(',')))
> 
> Is it possible to get rid of the lambda here, without having to define 
> another function just for this.
> 
> Is this the easiest/straight-forward way to do this?
> 
> regards,
> Suresh
-- 
http://mail.python.org/mailman/listinfo/python-list


Multiple assignment and the expression on the right side

2006-02-20 Thread Suresh Jeevanandam
Dear all,
I read in "Python in a Nutshell" that when we have multiple assignments 
made on a single line, it is equivalent to have those many simple 
assignments and that the right side is evaluated once for each 
assignment. [The wordings are mine. I am not sure if this is what he 
intended].

So, In the following code snippet I expected the values of c, d, e to 
be different. But they are not? I am missing something... What is it?
 >>> a = 12
 >>> def x(): global a; a+=1; return(a)
...
 >>> x()
13
 >>> a
13
 >>> c = d = e = x()
 >>> c
14
 >>> d
14
 >>> e
14
 >>>

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


Augmented assignment

2006-02-20 Thread Suresh Jeevanandam
Hi,
Is there any gain in performance because of augmented assignments.

x += 1  vs x = x+1

Or are both of them the same.

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


Re: Augmented assignment

2006-02-20 Thread Suresh Jeevanandam
Thanks Alex. I was not aware of mtimeit.

regards,
Suresh
Alex Martelli wrote:
> Suresh Jeevanandam <[EMAIL PROTECTED]> wrote:
> 
>> Hi,
>>   Is there any gain in performance because of augmented assignments.
>>
>>   x += 1  vs x = x+1
>>
>> Or are both of them the same.
> 
> Just *MEASURE*, man!
> 
> helen:~/apy alex$ python -mtimeit -s'x=0.0' 'x=x+1'
> 100 loops, best of 3: 0.507 usec per loop
> 
> helen:~/apy alex$ python -mtimeit -s'x=0.0' 'x+=1'
> 100 loops, best of 3: 0.504 usec per loop
> 
> Basically a dead draw, so use what's clearest to you.  And learn to use
> -mtimeit to satisfy most such curiosities much more effectively.
> 
> 
> Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Mutable numbers

2006-02-20 Thread Suresh Jeevanandam
# I am new to python.

In python all numbers are immutable. This means there is one object ( a 
region in the memory ) created every time we do an numeric operation. I 
hope there should have been some good reasons why it was designed this way.

But why not have mutable numbers also in the language. A type which 
would behave as follows:

a = MutableInt(12)
b = a

Now both a and b should refer to the same memory location. Any change in 
the object should get reflected in all the references.

a.assign(13) # Same memory location should be updated with value 13, b 
is also 13 now.

Now we can further optimize:

a.incrementOne() # equivalent to a++ in C++
a.decrementOne()

and the augmented assignment operation also could be made optimized.

In any application most of the operation is numerical. So, i think, we 
should get a good speed advantage with the availability of mutable 
numbers. What do you think ?

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


Re: Multiple assignment and the expression on the right side

2006-02-20 Thread Suresh Jeevanandam
Alex Martelli wrote:
> Suresh Jeevanandam <[EMAIL PROTECTED]> wrote:
> 
>> Dear all,
>>   I read in "Python in a Nutshell" that when we have multiple assignments
>> made on a single line, it is equivalent to have those many simple 
>> assignments and that the right side is evaluated once for each 
>> assignment. [The wordings are mine. I am not sure if this is what he 
>> intended].
> 
> Since the original text is:
> 
> """
> Each time the statement executes, the right-hand side expression is
> evaluated once. Each target gets bound to the single object returned by
> the expression.
> """

Alex,
I should have read carefully.

I think I got confused because of "Each time" in the sentence which 
gives a feeling that it gets executed several times. Maybe, It could 
have been just written, "When the statement gets executed, the right 
hand side is evaluated once, and the result is assigned to each of the 
target".

Thanks a lot.

regards,
Suresh

> it might be interesting to understand how you managed to translate ONCE
> into ONCE PER ASSIGNMENT TARGET.  I can most earnestly assure you that
> when I wrote ONCE I meant ONCE. If ONCE meant TWICE (or more), how could
> there be a guaranteed SINGLE OBJECT to which each target gets bound?
> 
>>   So, In the following code snippet I expected the values of c, d, e to
>> be different. But they are not? I am missing something... What is it?
> 
> A good command of English, maybe?  With that ONCE and SINGLE in there,
> no matter how much I try to, I just cannot see ambiguity in the words I
> had written.  Nevertheless, in your honor, I guess I will redundantly
> change the ONCE into JUST ONCE in the second edition (I do strive for
> maximum conciseness in the Nutshell, but I guess I can spare one extra
> four-letter word, even though this is the only time I ever heard anybody
> express any doubt or misunderstanding about this paragraph).
> 
> 
> Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Memory Leak in Python 2.5.1?

2007-06-05 Thread Suresh Kumar

Hi,

I am currently investigating what seems to be a memory leak in python.
(version 2.5.1). I have made python work with a custom memory sub-allocator
(pool). The idea is to  preallocate a pool of memory during initialization
of my application and ensure that Python doesn't make any system mallocs
(similar to max heap setting in java VM). With this arrangement, python
seems to run out of preallocated memory after few iterations of the
following code:

int main(int argc, char *argv[]){
  int i;
  mem_init(300);//Initialize the memory pool with 3M
  for (i=0;i<2000,i++){
 Py_Initialize();
 Sleep(1000);
 Py_Finalize();
  }
}


The above code runs out of memory after 1000 + iterations. To me this looks
like a memory leak, Does anyone out there have any idea whats happening
here?

Regards,
Suresh

--
"Everything of value that people get from religion can be had more honestly,
without presuming anything on insufficient evidence. The rest is
self-deception, set to music."
-- 
http://mail.python.org/mailman/listinfo/python-list

Execution speed question

2008-07-25 Thread Suresh Pillai
I am performing simulations on networks (graphs).  I have a question on 
speed of execution (assuming very ample memory for now).  I simplify the 
details of my simulation below, as the question I ask applies more 
generally than my specific case.  I would greatly appreciate general 
feedback in terms of computing and of course considerations specific to 
implementation in Python.

The nodes in my network may be ON or OFF.  The network starts off with 
all nodes in the OFF state.  I loop through the nodes.  For each node 
that is OFF, I consider some probability of it turning ON based on the 
states of its neighbours.  I MUST GO THROUGH ALL NODES BEFORE DECIDING 
WHICH ONES TO TURN ON.

So my question is whether it is faster to 

1. loop through a list of ALL nodes and check for OFF nodes using ifs 

or to 

2. loop through a container of OFF nodes and remove from this when they  
turn ON

The second would result in looping through less nodes, especially as the 
simulation progresses, but how does the cost of removal compare with 
cheap ifs and would the extra memory usage affect performance.

I an appreciate that the cost of the if check, the number of nodes, and 
the type of container I use will come into the answer.

In my case, the ifs are cheap boolean queries (whether the node is ON or 
OFF).  The number of nodes is very large: millions for sure, maybe tens 
of millions.  If considering (2), take note of my BOLD text above, which 
means I can't remove nodes as I iterate through them in the main loop.

I naturally started coding with (2), but couldn't decide on the best data 
structure for python.  A set seemed ideal for speedy removal, but then I 
can't iterate through them with out popping.  An ordered list?  Some 
creative solution with numpy arrays?

There is also the complication that since we are in interpreted python, 
what is theoretically the best data structure may not in reality be 
optimal unless it is a default system object or coded externally in a 
compiled module.

Of course, I will start experimenting to see what the execution 
difference is, but I would appreciate some suggestions from others re 
which is best and also on best data structure for (2).  

I'm not a newbie, so you can get technical with me python-wise and 
algorithm wise.  I realise it is a 'basic' question, but it is something 
that I have always wondered about (cheap ifs versus extra structure) and 
with the number of nodes I am considering, it actually becomes an issue.

Many Thanks,
Suresh
--
http://mail.python.org/mailman/listinfo/python-list


Re: Execution speed question

2008-07-25 Thread Suresh Pillai
That's a good comparison for the general question I posed.  Thanks.  
Although I do believe lists are less than ideal here and a different data 
structure should be used.

To be more specific to my case:
As mentioned in my original post, I also have the specific condition that 
one does not know which nodes to turn ON until after all the 
probabilities are calculated (lets say we take the top m for example).  
In this case, the second and third will perform worse as the second one 
will require a remove from the list after the fact and the third will 
require another loop through the nodes to build the new list.  
--
http://mail.python.org/mailman/listinfo/python-list


Re: Execution speed question

2008-07-25 Thread Suresh Pillai
On Fri, 25 Jul 2008 16:51:42 +0200, Fredrik Lundh wrote:

> Unless I'm missing something, your example keeps going until it's
> flagged *all* nodes as "on", which, obviously, kills performance for the
> first version as the probability goes down.  The OP's question was about
> a single pass (but he did mention "as the simulation progresses", so I
> guess it's fair to test a complete simulation.)

I was referring to multiple passes as in Iain' test cases.  Although not 
necessarily till all nodes are ON, let's say to to a large proportion at 
least. 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Execution speed question

2008-07-28 Thread Suresh Pillai
On Fri, 25 Jul 2008 08:08:57 -0700, Iain King wrote:

> On Jul 25, 3:39 pm, Suresh Pillai <[EMAIL PROTECTED]> wrote:
>> That's a good comparison for the general question I posed.  Thanks.
>> Although I do believe lists are less than ideal here and a different
>> data structure should be used.
>>
>> To be more specific to my case:
>> As mentioned in my original post, I also have the specific condition
>> that one does not know which nodes to turn ON until after all the
>> probabilities are calculated (lets say we take the top m for example).
>> In this case, the second and third will perform worse as the second one
>> will require a remove from the list after the fact and the third will
>> require another loop through the nodes to build the new list.
> 
> So you need to loops through twice regardless?  i.e. loop once to gather
> data on off nodes, do some calculation to work out what to turn on, then
> loop again to turn on the relevant nodes?  If so, then I think the
> functions above remain the same, becoming the 2nd loop. Every iteration
> you do a first loop over the off_nodes (or them all for (1)) to gather
> the data on them, perform your calculation, and then perform one of the
> above functions (minus the setup code at the begining; basically
> starting at the 'for') as a second loop, with the goes_on function now
> returning a value based on the calculation (rather than the calculation
> itself as I had it).  Performance should be similar.
> 
> Iain

If do I settle on an explicit loop to remove the nodes turned ON, then I 
realised this weekend that I could do this in the next iteration of the 
simulation (first loop above) and save some iteration overhead (the if 
checking will still be there of course).

And thanks for pointing out that constructing a new list, for long lists, 
is faster than simple removal.  It's obvious but I never really thought 
of it; good tip.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Execution speed question

2008-07-28 Thread Suresh Pillai
On Fri, 25 Jul 2008 09:22:06 -0600, Matthew Fitzgibbons wrote:

> As for different data structures, it largely depends on how you need to
> access the data. If you don't need to index the data, just loop through
> it, you might try a linked list. The performance hit in (2) is coming
> from the list del; using a linked list would make the removal constant
> rather than O(n), and may even execute faster than (3) as well.
> 
> -Matt

Yes, this was my first inclination.  So my question, as alluded to in my 
original post, is whether there are C compiled modules for linked lists, 
doubly linked lists, ordered lists ... (the standard data structures) 
somewhere, to get the extra performance out of them.

With python we have all built up creative ways of using the native 
structures for efficiency reasons.  This project was the first time (due 
to its extreme use of resources) that I've had to worry about these 
minute considerations of native vs new structure but also take into 
account native vs python level construct vs compiled module.

[P.S.  The linked list does compare well with (3) as expected.]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Execution speed question

2008-07-28 Thread Suresh Pillai
On Fri, 25 Jul 2008 05:46:56 -0700, Iain King wrote:

> or 3. build a new list every iteration intead of deleting from the old
> one:
> 
> while processing:
> new_off_list = []
> for x in off_list:
> if goes_on(x):
> on_list.append(x)
> else:
> new_off_list.append(x)
> off_list = new_off_list
> generation += 1
> 
> Iain

Or 4, since the order of my nodes doesn't matter:  swap the node to be 
deleted with the last node in the list and then remove the last node of 
the list.  This is the fastest to date, if using native structures, for 
low number nodes being deleted per cycle (def if only deleting one).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Execution speed question

2008-07-28 Thread Suresh Pillai
On Fri, 25 Jul 2008 17:05:27 -0400, Terry Reedy wrote:

> If the nodes do not have to be processed in any particular order, then
> you could keep them either in a dict, with the value being either On or
> Off (True,False)(plus connection data) or a pair of sets, one for On and
> one for Off.  The advantage of the dict is that the items would be fixed
> and only their values would change, but you needlessly scan through On
> items.   The advantage of the set pair is that you only scan through Off
> items but have to move some from Off to On.  I will not guess which
> would be faster over a complete run, or how this will compare with using
> lists.
> 
> tjr

Thanks for the reply.  As mentioned in my original post, sets came to 
mind straight way, doing it the way you suggest.  I alluded to, but 
didn't directly ask:

Since I am doing A LOT of loops over the nodes and the number of nodes is 
also huge, my concern using sets is that in order to iterate over the set 
in each step of my simulation, the set items need to be converted to a 
list every time.  So while removal from a set is much cheaper than say 
from a list, what about this conversion overhead in order to iterate over 
the items.

The dict suggestion is good.  Originally I had my nodes as objects, with 
a networkx object for the graph (which is a dict).  Since efficiency is 
the most important this for this piece of code, I may decide to forget 
about abstract nodes and put all attributes in a dict as you suggest.  
Too many permutations, which is why I made the original post, hoping 
wiser python coders could eliminate a few possibilities. :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Execution speed question

2008-07-28 Thread Suresh Pillai
On Mon, 28 Jul 2008 10:44:18 +0200, Suresh Pillai wrote:

> Since I am doing A LOT of loops over the nodes and the number of nodes
> is also huge, my concern using sets is that in order to iterate over the
> set in each step of my simulation, the set items need to be converted to
> a list every time.  So while removal from a set is much cheaper than say
> from a list, what about this conversion overhead in order to iterate
> over the items.

I could of course use the old trick of using a dictionary with 'None' 
values and then using iterkeys().  But I thought sets were supposed to 
replace this.  So maybe I should be asking a more basic question: is 
there any way to iterate over the items in a set other than converting to 
a list or using the pop() method.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Execution speed question

2008-07-28 Thread Suresh Pillai
On Mon, 28 Jul 2008 15:04:43 +0200, Suresh Pillai wrote:

> On Mon, 28 Jul 2008 10:44:18 +0200, Suresh Pillai wrote:
> 
>> Since I am doing A LOT of loops over the nodes and the number of nodes
>> is also huge, my concern using sets is that in order to iterate over
>> the set in each step of my simulation, the set items need to be
>> converted to a list every time.  So while removal from a set is much
>> cheaper than say from a list, what about this conversion overhead in
>> order to iterate over the items.
> 
> I could of course use the old trick of using a dictionary with 'None'
> values and then using iterkeys().  But I thought sets were supposed to
> replace this.  So maybe I should be asking a more basic question: is
> there any way to iterate over the items in a set other than converting
> to a list or using the pop() method.

Okay, please consider this my one absolutely stupid post for the year.  
I'd like to pretend it never happened but unfortunately the web doesn't 
allow that.  Having never used sets, I unfort read something that lead to 
it, but ...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Execution speed question

2008-07-29 Thread Suresh Pillai
On Mon, 28 Jul 2008 16:48:28 +0200, Suresh Pillai wrote:

> Okay, please consider this my one absolutely stupid post for the year.
> I'd like to pretend it never happened but unfortunately the web doesn't
> allow that.  Having never used sets, I unfort read something that lead
> to it, but ...

Okay, got some sleep and what I meant to ask, although equally basic, but 
not silly:

For sets, I presume they are built on top of or like dicts, and there is 
nothing crazy in the low level implementation so that I can be guaranteed 
that if I don't alter the set, then the order, although arbitrary, will 
be maintained in successive iterations over the contents?
--
http://mail.python.org/mailman/listinfo/python-list


Wouldn't it be nice if this worked?

2008-08-10 Thread Suresh V.

class A:
def add(self, x, y):
return x+y

class B:
pass

B.add = A.add

print B().add(1, 2) <- gives TypeError: unbound method add() must
   be called with A instance as first argument

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


Re: module: zipfile.writestr - line endings issue

2007-08-15 Thread Suresh Babu Kolla
Paul Carter wrote:
> On Aug 14, 1:32 pm, towers <[EMAIL PROTECTED]> wrote:
>> Thanks - your code works for me also.
>>
>> But I still get the issue when I read the file directly and add it to
>> the archive.
>>
>> Say if I:
>>
>> 1. Use the test.csv file created with your code - currently the line
>> endings look good (viewed in notepad on Win XP)
>> 2. Run the following code:
>>
>> # begin code
>> import zipfile
>> import os.path
>>
>> # Now, create the zipfile
>> dfile = open('test.csv', 'r')
>> zip_file = zipfile.ZipFile(r'C:\temp\ice\line endings\test.zip', 'w',
>> zipfile.ZIP_DEFLATED)
>> zip_file.writestr('test.csv',dfile.read())
>> dfile.close()
>> zip_file.close()
>>
>> 3. Then extract the file and the file endings have been corrupted. Now
>> one long line in notepad. (Other programs interpret correctly though.)
>>
>> Maybe the issue lies with this way (i.e. dfile.read()) of writing the
>> file to the archive...possibly.
>>
>> Damon
>>
> 
> Please don't top post.
> 
> The problem is with how you are opening the file. You need to open in
> binary mode if you wish to read your file unaltered. Also, file() is
> preferred over open() these days I think. Use:
> 
> dfile = file('test.csv', 'rb')

 From Python 2.5 library documentation.


  When opening a file, it's preferable to use `open()' instead of
  invoking this constructor directly.  `file' is more suited to type
  testing (for example, writing `isinstance(f, file)').


Python documentation seem to recommend using open(). I personally prefer
to use open, just because python open has same signature as POSIX open, 
even beginner programmers can understand the intent of the code clearly.

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


Re: subprocess -popen - reading stdout from child - hangs

2007-09-22 Thread Suresh Babu Kolla
[EMAIL PROTECTED] wrote:
> Let's say I have this Python file called loop.py:
> 
> import sys
> print 'hi'
> sys.stdout.flush()
> while 1:
> pass
> 
> And I want to call it from another Python process and read the value
> 'hi'.  How would I do it?
> 
> So far I have tried this:
> 
 proc = subprocess.Popen('python 
 /home/chiefinnovator/loop.py',shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE)
 proc.stdout.read()
> 

 From python documentation

`read([size])'
  Read at most SIZE bytes from the file (less if the read hits `EOF'
  before obtaining SIZE bytes).  If the SIZE argument is negative or
  omitted, read all data until `EOF' is reached.  The bytes are
  returned as a string object.  An empty string is returned when
  `EOF' is encountered immediately.  (For certain files, like ttys,
  it makes sense to continue reading after an `EOF' is hit.)  Note
  that this method may call the underlying C function `fread()' more
  than once in an effort to acquire as close to SIZE bytes as
  possible. Also note that when in non-blocking mode, less data than
  what was requested may be returned, even if no SIZE parameter was
  given.

  read call in your code is waiting for EOF, since the script never exits
  EOF is not reached.

  Change read code to

  proc.stdout.readline()

  or

  remove while 1 loop from loop.py.

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