Python form Unix to Windows
Hi friends, We are changing the python application from Unix to Windows. The source code of Python application should work well in windows. How to make changed to windows environment. In Python code we have login module, ftp, socket programming. Please help in changing the code from Unix envirnment to Windows Environment. Thanks in Advance. Regards, Pradeep -- http://mail.python.org/mailman/listinfo/python-list
syntax error : first python program
I have this file in linux === sample.py #!/usr/bin/env python name = "blah" print name --- I executed this bash# ./sample.py File "./sample.py", line 2 name = "blah" ^ bash# /usr/bin/python sample.py File "sample.py", line 2 name = "blah" ^ SyntaxError: invalid syntax Any one knows , whats the syntax error here? -- http://mail.python.org/mailman/listinfo/python-list
Issue in software
I I couldn't get the solution for this issue since last week will you please help me to solve this issue the issue is when I opened command prompt this below message will Pop up "The program can't start because api-ms-win-crt-runtime-[1-1-0.dl] is missing from your computer.try reinstalling the program to fix this problem." I tried to solve several times and many times but I didn't get any expected outcome. Can you please help me please. -- https://mail.python.org/mailman/listinfo/python-list
Search and Replace of string in a yaml file
Hi all, I have several yaml files in a directory around 100s. I have some values and my script should search a string(reading from the JSON file) from the series of yaml files and run some validation like the key of the file that is updated in the yaml file and run some basic validation tests like data integrity of the replaced string with the source string read from JSON. Can anyone suggest some reliable and efficient method to achieve this and appreciate some examples for the same? Regards Pradeep -- https://mail.python.org/mailman/listinfo/python-list
How to pass username and password in the curl requests using requests python module
Can anyone pls help in this regard? -- https://mail.python.org/mailman/listinfo/python-list
numpy results in segmentation fault
Hi , I was trying to solve the hackerrank and was using python 3.7.x. https://www.hackerrank.com/challenges/np-concatenate/problem While running the code sometimes I get success result and sometimes it fails with "Segmentation Fault" at Hacker rank UI. I dont have any clue why the code is crashing ? Does anyone have any idea? Regards Pradeep import numpy n,m,p = map(int,input().split()) tgt_arr1 = [] for i in range(n): row = list(map(int,input().split())) tgt_arr1.append(row) tgt_arr2 = [] for j in range(m): row = list(map(int,input().split())) tgt_arr2.append(row) num_arr1 = numpy.array(tgt_arr1,int) num_arr2 = numpy.array(tgt_arr2,int) print(numpy.concatenate((num_arr1,num_arr2),axis=0)) -- https://mail.python.org/mailman/listinfo/python-list
Re: numpy results in segmentation fault
Yes it is crashing in the hackerrank site and the testcases fails with segmentation fault. I tried to install numpy with 3.7.3 and it is for some reason not working and after import when I run import numpy at python console and press enter I get >>? i,e its not working properly. Can you please help letting me know the python and numpy compatibility matrix or I am missing anything? I tried some of the numpy code from the other github and it also fails with the segmentation fault :-(. I am guessing some numpy version compatility issue or some environment issue. On Thu, Sep 12, 2019 at 8:00 PM Thomas Jollans wrote: > On 12/09/2019 15.53, Pradeep Patra wrote: > > Hi , > > > > I was trying to solve the hackerrank and was using python 3.7.x. > > https://www.hackerrank.com/challenges/np-concatenate/problem > > > > While running the code sometimes I get success result and sometimes it > > fails with "Segmentation Fault" at Hacker rank UI. I dont have any clue > why > > the code is crashing ? Does anyone have any idea? > > > Are you sure it's your code that's crashing, and not something beyond > your control? (Such as the software that is starting Python for you) > Does it depend on the input? Can you reproduce the issue in a controlled > environment (i.e. on your own PC)? > > > > > > Regards > > Pradeep > > > > import numpy > > > > n,m,p = map(int,input().split()) > > tgt_arr1 = [] > > for i in range(n): > > row = list(map(int,input().split())) > > tgt_arr1.append(row) > > tgt_arr2 = [] > > for j in range(m): > > row = list(map(int,input().split())) > > tgt_arr2.append(row) > > > > num_arr1 = numpy.array(tgt_arr1,int) > > num_arr2 = numpy.array(tgt_arr2,int) > > > > print(numpy.concatenate((num_arr1,num_arr2),axis=0)) > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
regular expressions help
Hi all, I was playing around with regular expressions and testing the simple regular expression and its notworking for some reason. I want to search "my-dog" at any of the place in a string and return the index but its not working. I tried both in python 3.7.3 and 2.7.x. Can anyone please help? I tried re.search, re.finditer, re.findall and none of them is not working for me. import re mystr= "where is my-dog" pattern=re.compile(r'^my\-dog$') matches = re.search(mystr) print(matches) In the above example both cases(match/not match) the matches returns "None" I tried re.finditer() and then a loop to find all the occurences of the pattern in the string but even if there is no error but i could not find the match. Can anyone help me in this regard? Regards Pradeep -- https://mail.python.org/mailman/listinfo/python-list
Re: regular expressions help
I am using python 2.7.6 but I also tried on python 3.7.3. On Thursday, September 19, 2019, Pradeep Patra wrote: > Beginning of the string. But I tried removing that as well and it still > could not find it. When I tested at www.regex101.com and it matched > successfully whereas I may be wrong. Could you please help here? > > On Thursday, September 19, 2019, David wrote: > >> On Thu, 19 Sep 2019 at 17:51, Pradeep Patra >> wrote: >> > >> > pattern=re.compile(r'^my\-dog$') >> > matches = re.search(mystr) >> > >> > In the above example both cases(match/not match) the matches returns >> "None" >> >> Hi, do you know what the '^' character does in your pattern? >> > -- https://mail.python.org/mailman/listinfo/python-list
Re: regular expressions help
Thanks David for your quick help. Appreciate it. When I tried on python 2.7.3 the same thing you did below I got the error after matches.group(0) as follows: AttributeError: NoneType object has no attribute 'group'. I tried to check 'None' for no match for re.search as the documentation says but it's not working. Unfortunately I cannot update the python version now to 2.7.13 as other programs are using this version and need to test all and it requires more testing. Any idea how I can fix this ? I am ok to use any other re method(not only tied to re.search) as long as it works. On Thursday, September 19, 2019, David wrote: > On Thu, 19 Sep 2019 at 18:41, Pradeep Patra > wrote: > > On Thursday, September 19, 2019, Pradeep Patra > wrote: > >> On Thursday, September 19, 2019, David wrote: > >>> On Thu, 19 Sep 2019 at 17:51, Pradeep Patra > wrote: > > >>> > pattern=re.compile(r'^my\-dog$') > >>> > matches = re.search(mystr) > > >>> > In the above example both cases(match/not match) the matches returns > "None" > > >>> Hi, do you know what the '^' character does in your pattern? > > >> Beginning of the string. But I tried removing that as well and it still > could not find it. When I tested at www.regex101.com and it matched > successfully whereas I may be wrong. Could you please help here? > > > I am using python 2.7.6 but I also tried on python 3.7.3. > > $ python2 > Python 2.7.13 (default, Sep 26 2018, 18:42:22) > [GCC 6.3.0 20170516] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import re > >>> mystr= "where is my-dog" > >>> pattern=re.compile(r'my-dog$') > >>> matches = re.search(mystr) # this is syntax error, but it is what you > showed above > Traceback (most recent call last): > File "", line 1, in > TypeError: search() takes at least 2 arguments (1 given) > >>> matches = re.search(pattern, mystr) > >>> matches.group(0) > 'my-dog' > >>> > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: regular expressions help
Thanks David /Anthony for your help. I figured out the issue myself. I dont need any ^, $ etc to the regex pattern and the plain string (for exp my-dog) works fine. I am looking at creating a generic method so that instead of passing my-dog i can pass my-cat or blah blah. I am thinking of creating a list of probable combinations to search from the list. Anybody have better ideas? On Thu, Sep 19, 2019 at 3:46 PM David wrote: > On Thu, 19 Sep 2019 at 19:34, Pradeep Patra > wrote: > > > Thanks David for your quick help. Appreciate it. When I tried on python > 2.7.3 the same thing you did below I got the error after matches.group(0) > as follows: > > > > AttributeError: NoneType object has no attribute 'group'. > > > > I tried to check 'None' for no match for re.search as the documentation > says but it's not working. > > > > Unfortunately I cannot update the python version now to 2.7.13 as other > programs are using this version and need to test all and it requires more > testing. Any idea how I can fix this ? I am ok to use any other re > method(not only tied to re.search) as long as it works. > > Hi again Pradeep, > > We are now on email number seven, so I am > going to try to give you some good advice ... > > When you ask on a forum like this for help, it is very > important to show people exactly what you did. > Everything that you did. In the shortest possible > way that demonstrates whatever issue you are > facing. > > It is best to give us a recipe that we can follow > exactly that shows every step that you do when > you have the problem that you need help with. > > And the best way to do that is for you to learn > how to cut and paste between where you run > your problem code, and where you send your > email message to us. > > Please observe the way that I communicated with > you last time. I sent you an exact cut and paste > from my terminal, to help you by allowing you to > duplicate exactly every step that I made. > > You should communicate with us in the same > way. Because when you write something like > your most recent message > > > I got the error after matches.group(0) as follows: > > AttributeError: NoneType object has no attribute 'group'. > > this tells us nothing useful!! Because we cannot > see everything you did leading up to that, so we > cannot reproduce your problem. > > For us to help you, you need to show all the steps, > the same way I did. > > Now, to help you, I found the same old version of > Python 2 that you have, to prove to you that it works > on your version. > > So you talking about updating Python is not going > to help. Instead, you need to work out what you > are doing that is causing your problem. > > Again, I cut and paste my whole session to show > you, see below. Notice that the top lines show that > it is the same version that you have. > > If you cut and paste my commands into > your Python then it should work the same way > for you too. > > If it does not work for you, then SHOW US THE > WHOLE SESSION, EVERY STEP, so that we can > reproduce your problem. Run your python in a terminal, > and copy and paste the output you get into your message. > > $ python > Python 2.7.3 (default, Jun 20 2016, 16:18:47) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import re > >>> mystr = "where is my-dog" > >>> pattern = re.compile(r'my-dog$') > >>> matches = re.search(pattern, mystr) > >>> matches.group(0) > 'my-dog' > >>> > > I hope you realise that the re module has been used > by thousands of programmers, for many years. > So it's extremely unlikely that it "doesn't work" in a way that > gets discovered by someone who hardly knows how to use it. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
itertools query
Hi all, I have written a small program to generate all the combinations of a and b of the array. I want (6,7) tuple also included. Can anybody suggest what change I should make to get 6,7 included in my output? Any suggestions Output: [(5,), (6,), (5, 6), (7,), (8,), (7, 8)] from itertools import chain, combinations a = [5,6] b = [7,8] ar=[] br=[] def all_subsets(ss): return chain(*map(lambda x: combinations(ss, x), range(1, len(ss)+1))) for subset in all_subsets(a): print(subset) ar.append(subset) for subset in all_subsets(b): print(subset) br.append(subset) fr=ar+br print(fr) -- https://mail.python.org/mailman/listinfo/python-list
Re: itertools query
I don't need other combination except 6,7 On Saturday, September 28, 2019, Piet van Oostrum wrote: > Pradeep Patra writes: > > > Hi all, > > > > I have written a small program to generate all the combinations of a and > b > > of the array. I want (6,7) tuple also included. Can anybody suggest what > > change I should make to get 6,7 included in my output? Any suggestions > > > > Why (6,7)? What about (5,7), (5,8) and (6,8)? > -- > Piet van Oostrum > WWW: http://piet.vanoostrum.org/ > PGP key: [8DAE142BE17999C4] > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
doubt in curses module
hii, iam new to python. i want to use function keys in my program, so i went through the curses module, but in that module it shows a different window object and after pressing the our desired function key in it, that will return the ascii value of that key to the command prompt. so, i want to hide or dissable the window object, can anyone tell me how it will be possible... it is very urgent -- http://mail.python.org/mailman/listinfo/python-list
connecting webservers through HTTP port using python
hii iam working on socket programming, i've to connect webservers through HTTP port and send/receive data.. so currently i'm installed apache server and trying to connect that server using python. so any tell me how to connect the apache server by python code. give suggestions.. -- http://mail.python.org/mailman/listinfo/python-list
How to get inputs for a python program that run from another python program
I would like to know how to pass keyboard input for a python script
which is ran by another script.
for eg:
hello1.py:
import os
if __name__=='__main__':
print "I will call this other program called hello.py"
os.system("python hello.py")
print "hello1.py"
hello.py:
import os
if __name__=='__main__':
print "press ENTER to display"
#code wer if the user hits enter
print "hello"
#else the user hits any other keyboard button:
sys.exit()
now wen i run hello1.py,i want the some function or utility in
hello1.py that can pass the keyboard i/p to hello.py .
--
http://mail.python.org/mailman/listinfo/python-list
how to find the OS name..??
How do i determine the type of OS i'm working on using python??(i.e whether CentOS,Fedora,SLES,...along with the version) -- http://mail.python.org/mailman/listinfo/python-list
FInd files with .so extension
HI, How do i find files with .so extension using python . -- http://mail.python.org/mailman/listinfo/python-list
Re: FInd files with .so extension
On May 3, 11:27 am, kaens <[EMAIL PROTECTED]> wrote:
> do YOU mean hit "reply to all" not "reply?"
>
> On 5/3/07, kaens <[EMAIL PROTECTED]> wrote:
>
> > do you mean
> > filelst.append(i)?
>
> > On 5/3/07, rishi pathak <[EMAIL PROTECTED]> wrote:
> > > May be this would work
> > > import os
> > > grep="so"
> > > dir="."
> > > lst = os.listdir(dir)
> > > filelst=[]
> > > for i in lst:
> > > if i.split(".")[len(i.split("."))-1] == grep:
> > > lst.append(i)
> > > print lst
>
> > > On 2 May 2007 21:58:41 -0700, pradeep nair <[EMAIL PROTECTED]> wrote:
> > > > HI,
>
> > > > How do i find files with .so extension using python .
>
> > > > --
> > > >http://mail.python.org/mailman/listinfo/python-list
>
> > > --
> > > Regards--
> > > Rishi Pathak
> > > National PARAM Supercomputing Facility
> > > Center for Development of Advanced Computing(C-DAC)
> > > Pune University Campus,Ganesh Khind Road
> > > Pune-Maharastra
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list
How to find the present working directory using python.
how to find out the present working directory using python.
os.system('pwd') works good. But i need some specific one in
python rather than embedding shell command into python.
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to find the present working directory using python.
On May 4, 12:05 pm, SamG <[EMAIL PROTECTED]> wrote:
> On May 4, 12:03 pm, pradeep nair <[EMAIL PROTECTED]> wrote:
>
> > how to find out the present working directory using python.
>
> > os.system('pwd') works good. But i need some specific one in
> > python rather than embedding shell command into python.
>
> os.path.getcwd()
Thank u...
--
http://mail.python.org/mailman/listinfo/python-list
How to convert None to null value
Hi ,
i am trying to insert records from one table to another table in postgres
sql using the the following code
posConn.query("insert into
usr(usr_id,usr_name,usr_passwd,grp_cde,usr_type,usr_chk_till_val, \
usr_active,usr_daily_auth,usr_lst_login,usr_lst_logout,usr_shift_id,usr_role_level)
values \
('%s','%s','%s',%s,%i,%d,'%s',%i,%i,%i,%i,%i)"
%(row[0],row[1],row[2],row[3],row[4],row[5], \
row[7],row[8],row[10],row[11],row[12],row[14]) )
here row[4] column is having null value so python consides it as None but
will insert into the table it inserts as None not null value
please help how to convert None to null value
--
http://mail.python.org/mailman/listinfo/python-list
Re: object inheritance
Can you tell any specific use case for doing this?
Regards,
Pradeep
On 10/26/07, Anand <[EMAIL PROTECTED]> wrote:
> I am trying to implement some kind of object inheritance. Just like
> one class can extend from another, I want to do the same on objects
> dynamically.
>
> I just thought that I can share my excitement here.
>
> Suppose there are classes A and B and their instances a and b.
>
> class A:
> def foo(self): self.say('foo')
> def say(self, msg):
> print 'a.say', msg
>
> class B:
> def say(self, msg):
> print 'b.say', msg
>
> a = A()
> b = B()
>
> I want b to inherit the behavior of a.
>
> >>> b.extend_from(a)
> >>> b.foo()
> b.say foo
>
> I looked around and found that some people talked about similar ideas,
> but didn't find any concrete implementation.
>
> I came up with the following implementation using meta-classes.
>
> class ExtendMetaClass(type):
> def __init__(cls, *a, **kw):
> # take all attributes except special ones
> keys = [k for k in cls.__dict__.keys() if not
> k.startswith('__')]
> d = [(k, getattr(cls, k)) for k in keys]
>
> # remove those attibutes from class
> for k in keys:
> delattr(cls, k)
>
> # remember then as dict _d
> cls._d = dict(d)
>
> def curry(f, arg1):
> def g(*a, **kw):
> return f(arg1, *a, **kw)
> g.__name__ = f.__name__
> return g
>
> def _getattr(self, name):
> """Get value of attribute from self or super."""
> if name in self.__dict__:
> return self.__dict__[name]
> elif name in self._d:
> value = self._d[name]
> if isinstance(value, types.MethodType):
> return curry(value, self)
> else:
> return value
> else:
> if self._super != None:
> return self._super._getattr(name)
> else:
> raise AttributeError, name
>
> def __getattr__(self, name):
> """Returns value of the attribute from the sub object.
> If there is no sub object, self._getattr is called.
> """
> if name.startswith('super_'):
> return self._super._getattr(name[len('super_'):])
>
> if self._sub is not None:
> return getattr(self._sub, name)
> else:
> return self._getattr(name)
>
> def extend_from(self, super):
> """Makes self extend from super.
> """
> self._super = super
> super._sub = self
>
> cls.__getattr__ = __getattr__
> cls._getattr = _getattr
> cls._super = None
> cls._sub = None
> cls.extend_from = extend_from
>
> class Extend:
> __metaclass__ = ExtendMetaClass
> def __init__(self, super=None):
> if super:
> self.extend_from(super)
>
> And the above example becomes:
>
> class A(Extend):
> def foo(self): self.say('foo')
> def say(self, msg):
> print 'a.say', msg
>
> class B(Extend):
> def say(self, msg):
> print 'b.say', msg
> # self.super_foo calls foo method on the super object
> self.super_say('super ' + msg)
>
> a = A()
> b = B()
>
> >>> b.extend_from(a)
> >>> b.foo()
> b.say foo
> a.say super foo
>
> There are one issue with this approach. Once b extends from a,
> behavior of a also changes, which probably should not. But that
> doesn't hurt me much.
>
> Any comments?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: object inheritance
On Friday 26 Oct 2007 6:21:57 pm Anand wrote: > On Oct 26, 5:31 pm, "Pradeep Jindal" <[EMAIL PROTECTED]> wrote: > > Can you tell any specific use case for doing this? > > I have many implementaions of a db interface. > > SimpleDB - simple implementation > BetterDB - optimized implementation > CachedDB - an implementation with caching of queries > RestrictedDB - implementation with permissions > > Now, I want to combine these implementations and use. > Typical use case scenarios are: > > db = RestrictedDB(CachedDB(SimpleDB())) > db = RestrictedDB(SimpleDB()) > db = RestrictedDB(BetterDB()) > db = RestrictedDB(CachedDB(BetterDB()) > db = CachedDB(SimpleDB()) > etc.. I agree with Duncan. According to me, this should be called Delegation rather than inheritance. And delegation should work without any conflicts of identifier names and all that. I think, it should be all about several objects implementing a protocol (interface) and that should work cleanly. -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLObject - Connect to established DB with non-int 'id' field
On Saturday 20 Oct 2007 5:43:48 am Sean DiZazzo wrote: > Hi all, > > I am just beginning with TurboGears and have run into a problem with > SQLObject. > > I'm trying to connect to an established mysql DB, and use TurboGears > to display results from the DB only. The problem is that the DB > already has an 'id' field that is a string as opposed to an int. > SQLObject complains because it wants to use the id field for it's own > purposes. > > How can I use TurboGears to get data out of this DB? > > Thanks in advance. > > ~Sean I know I am not exactly answering your question, but its much better to use sqlalchemy when you already have the databases setup. And especially when you can not make any changes to existing database schemas. - Pradeep -- http://mail.python.org/mailman/listinfo/python-list
Re: parse text file
On Tuesday 30 Oct 2007 12:06:57 pm william paul wrote: > Hi: > > I am new to this list and new to Python. I have a text file that looks > like: 4 50 > 3 900 > ... > > I want to be able to remove from each line everything up to ">" or "]" > sign. For example: 4 50 > 3 900 > 7 400 > > ... > 9 70 > > How can I do this? > > Thank you > > William > > > > __ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com You can use regular expressions module like this. >>> import re >>> match_upto_brackets = re.compile(r'.*[>\]}](.*)') >>> match_upto_brackets.sub(r'\1', ' 4 50').strip() '4 50' >>> match_upto_brackets.sub(r'\1', '>> match_upto_brackets.sub(r'\1', '>> Pradeep -- http://mail.python.org/mailman/listinfo/python-list
Iterable Flattener with Depth.
Hi, 5 minute solution to one of my requirements. I wanted to flatten iterables upto a specific depth. To be true, didn't search for it on the internet prior to writing this one. def flatten_iter(my_iter, depth=None): """my_iter can be a iterable except string containing nested iterables upto any depth. This function will flat all (except string) down to a list containing all the elements in nested-order. To add to it you can specify optional depth (int or long) argument and the function will flatten the iterable upto that depth (nesting). """ if not hasattr(my_iter, '__iter__') or isinstance(my_iter, basestring): return [my_iter] elif depth != None and depth <= 0: return my_iter temp = [] for x in my_iter: temp.extend(flatten_iter(x, None if depth == None else depth-1)) return temp py> temp = [1,[2,[3,4,5],'bash'],6,[7,[8,[9,10,['hi', 'hello', 11, 12] py> flatten_iter(temp,1) [1, 2, [3, 4, 5], 'bash', 6, 7, [8, [9, 10, ['hi', 'hello']]], 11, 12] py> flatten_iter(temp,2) [1, 2, 3, 4, 5, 'bash', 6, 7, 8, [9, 10, ['hi', 'hello']], 11, 12] py> flatten_iter(temp) [1, 2, 3, 4, 5, 'bash', 6, 7, 8, 9, 10, 'hi', 'hello', 11, 12] py> flatten_iter(temp,3) [1, 2, 3, 4, 5, 'bash', 6, 7, 8, 9, 10, ['hi', 'hello'], 11, 12] Any comments? Thanks - Pradeep -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterable Flattener with Depth.
On Friday 02 Nov 2007 10:43:45 pm Ian Clark wrote: > thebjorn wrote: > > On Nov 2, 6:32 am, praddy <[EMAIL PROTECTED]> wrote: > >> On Nov 1, 5:03 pm, [EMAIL PROTECTED] wrote: > >>> Pradeep Jindal: > >>>> Any comments? > >>> > >>> Something with similar functionality (plus another 20 utility > >>> functions/classes or so) has probably to go into the std lib... :-) > >>> Bye, > >>> bearophile > >> > >> Same Here! > >> > >> - Pradeep > > > > Yeah, everyone has to write a flatten sooner or later :-) My version > > is at: > > > > http://blog.tkbe.org/archive/python-flatten/ > > > > -- bjorn > > And here is mine. Note that it is very similar to Michael Spencer's > implementation[1]. The only difference is that this adds a depth counter. > > def iflat(itr, depth=0): >itr = iter(itr) >stack = [] >cur_depth = 0 > >while True: > try: >elem = itr.next() >if hasattr(elem, "__iter__") and cur_depth < depth: > stack.append(itr) > itr = iter(elem) > cur_depth += 1 >else: > yield elem > except StopIteration: >if not stack: > raise StopIteration >cur_depth -= 1 >itr = stack.pop() > > > if __name__ == "__main__": >test1 = ((0, 1, 2), ((3, 4), 5), (((6, 7), 8), 9)) >test2 = [1,[2,[3,4,5],'bash'],6,[7,[8,[9,10,['hi', 'hello', 11, 12] > >for x in (test1, test2): > print > print list(iflat(x)) > print > print list(iflat(x, 1)) > print list(iflat(x, 2)) > print list(iflat(x, 3)) > print list(iflat(x, 4)) > print iflat(x, 10) > > Ian > > [1] http://mail.python.org/pipermail/python-list/2005-March/312022.html Very nice non-recursive (iterative) implementation of the thing with required features. Yours is double faster than mine if depth is not specified, Mine is double faster than yours if depth is specified. And my main aim was the depth thingy. What do you think? - Pradeep -- http://mail.python.org/mailman/listinfo/python-list
Urgent : How to do memory leaks detection in python ?
Dear All, I am working on the python tools that process a huge amount of GIS data. These tools encountering the problem of memory leaks. Please suggest what are the different ways to detect the memory leaks in python ? This is very critical problem for me. Help needed urgently. Thanks & Regards, Pradeep -- http://mail.python.org/mailman/listinfo/python-list
Urgent : How to do memory leaks detection in python ?
Dear All, I am working on the python tools that process a huge amount of GIS data. These tools encountering the problem of memory leaks. Please suggest what are the different ways to detect the memory leaks in python ? This is very critical problem for me. Help needed urgently. Thanks & Regards, Pradeep -- http://mail.python.org/mailman/listinfo/python-list
Urgent : How to do memory leaks detection in python ?
Dear All, I am working on the python tools that process a huge amount of GIS data. These tools encountering the problem of memory leaks. Please suggest what are the different ways to detect the memory leaks in python ? This is very critical problem for me. Help needed urgently. Thanks & Regards, Pradeep -- http://mail.python.org/mailman/listinfo/python-list
RE: Urgent : How to do memory leaks detection in python ?
Thanks for your inputs !!! I have installed python v 2.5 on my Linux machine and executing the tool again. I would like to share the memory status( using free -m command ) before and after the execution of the tool. BEFORE EXECUTION total used free sharedbuffers cached Mem: 1006148*858* 0 8 92 -/+ buffers/cache: 46960 Swap: 2047 0 2047 AFTER EXECUTION === total used free sharedbuffers cached Mem: 1006940 *66* 0 49846 -/+ buffers/cache: 44962 Swap: 2047 0 2047 I am unable to find out why *66 MB* system memory is left after tool execution ? If python does not have memory leaks then where this memory is going ? I have explored few urls (as given below) related to memory leak in python : http://www.nightmare.com/medusa/memory-leaks.html http://mail.python.org/pipermail/tutor/1999-April/000162.html Please comment !!! -Original Message- *From:* [EMAIL PROTECTED] [mailto: [EMAIL PROTECTED] *On Behalf Of *tsuraan *Sent:* 16 March 2008 8:27 AM *To:* [email protected] *Subject:* Re: Urgent : How to do memory leaks detection in python ? > Python doesn't have memory leaks. Yeah, interesting bit of trivia: python is the world's only non-trivial program that's totally free of bugs. Pretty exciting! But seriously, python 2.4, at least, does have some pretty trivially exposed memory leaks when working with strings. A simple example is this: >>> letters = [chr(c) for c in range(ord('a'), ord('z'))+range(ord('A'), ord('Z'))] >>> ary = [] >>> for a in letters: ... for b in letters: ... for c in letters: ...for d in letters: ... ary.append(a+b+c+d) ... >>> del(ary) >>> import gc >>> gc.collect() 0 The VM's memory usage will never drop from its high point of (on my computer) ~200MB. Since you're using GIS data, this could be what you're running into. I haven't been able to upgrade my systems to python 2.5, but from my tests, that version did not have that memory leak. Nobody seems interesting in backporting fixes from 2.5 to 2.4, so you're probably on your own in that case as well, if upgrading to python 2.5 isn't an option or isn't applicable to your situation. -- http://mail.python.org/mailman/listinfo/python-list
ERROR: Python C API version mismatch for module dbi
Hi All, I have upgraded python v2.5.2 from python v2.4.3. The upgradation results into following error: "Python C API version mismatch for module dbi: This Python has API version 1013, module dbi has version 1012." Please suggest, how to resolve this error to proceed further. Regards, Pradeep Rai -- http://mail.python.org/mailman/listinfo/python-list
Re:Re: ERROR: Python C API version mismatch for module dbi
-On [20080331 12:29], Pradeep Rai ([EMAIL PROTECTED]) wrote: >I have upgraded python v2.5.2 from python v2.4.3. The upgradation >results into following error: "Python C API version mismatch for module >dbi: This Python has API version 1013, module dbi has version 1012." Did you copy everything from site-packages of the old one to the new one? -- Jeroen Ruigrok van der Werven / asmodai CF[ EtbN @ f EFF *http://www.in-nomine.org/* <http://www.in-nomine.org/> | * http://www.rangaku.org/* <http://www.rangaku.org/> If you're afraid of dyin', then you're holding on. You see devils tearing your life away. But if you have made your peace, then the devils are really angels, freeing you from the earth... -- http://mail.python.org/mailman/listinfo/python-list
Re: ERROR: Python C API version mismatch for module dbi
Yes, i have copied everything from site-packages of the old one to the new one. Regards, Pradeep -On [20080331 12:29], Pradeep Rai ([EMAIL PROTECTED]) wrote: >I have upgraded python v2.5.2 from python v2.4.3. The upgradation >results into following error: "Python C API version mismatch for module >dbi: This Python has API version 1013, module dbi has version 1012." Did you copy everything from site-packages of the old one to the new one? -- Jeroen Ruigrok van der Werven / asmodai CF[ EtbN @ f EFF *http://www.in-nomine.org/* <http://www.in-nomine.org/> | * http://www.rangaku.org/* <http://www.rangaku.org/> If you're afraid of dyin', then you're holding on. You see devils tearing your life away. But if you have made your peace, then the devils are really angels, freeing you from the earth... -- http://mail.python.org/mailman/listinfo/python-list
Re: ERROR: Python C API version mismatch for module dbi
Hi Steve, Can you guide me how to install a 2.5 version of dbi for it to work ? Thanks !! Pradeep Pradeep Rai wrote: > Hi All, > > I have upgraded python v2.5.2 from python v2.4.3. The upgradation > results into following error: > "Python C API version mismatch for module dbi: This Python has API > version 1013, module dbi has version 1012." > > Please suggest, how to resolve this error to proceed further. > > Regards, > Pradeep Rai > > Don't try and drag 2.4 extension modules into the 2.5 environemnt. You will have to install a 2.5 version of dbi for it to work. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC *http://www.holdenweb.com/* <http://www.holdenweb.com/> -- *http://mail.python.org/mailman/listinfo/python-list*<http://mail.python.org/mailman/listinfo/python-list> -- http://mail.python.org/mailman/listinfo/python-list
Re: ERROR: Python C API version mismatch for module dbi
Thanks !! I will try do so. Regards, Pradeep -On [20080331 12:56], Pradeep Rai ([EMAIL PROTECTED]) wrote: >Can you guide me how to install a 2.5 version of dbi for it to work ? Same way you installed dbi for 2.4 just make sure the called python executable is the 2.5 one. -- Jeroen Ruigrok van der Werven / asmodai CF[ EtbN @ f EFF *http://www.in-nomine.org/* <http://www.in-nomine.org/> | * http://www.rangaku.org/* <http://www.rangaku.org/> Sometimes things stare us in the face and we are too blind to see... -- http://mail.python.org/mailman/listinfo/python-list
Required help on python-time module
I am a newbie to python even mobile side also. I am using openmoko device, there I installed stripped down python from feed path's and I need tzset() of time module for my application but when running my application. time.tzset() at above line getting "no attribute tzset() for module" . So tzset() is not implemented in time module that I installed. To copy separately time module from desktop system to device it is shared library time.so , it's not worked. any suggetion or help highly appreciated. Thanks, opendeep. Unlimited freedom, unlimited storage. Get it now, on http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/-- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Tkinter Programming by John Grayson
On Fri, Jan 22, 2010 at 6:48 AM, Ethan Furman wrote: > Peter wrote: >> >> On Jan 15, 9:12 am, Kevin Walzer wrote: On Jan 15, 6:24 am, Mark Roseman wrote: > > Peter wrote: >> >> Besides, the book is mainly about using Python with Tkinter - and >> Tkinter hasn't changed that much since 2000, so I believe it is just >> as relevant today as it was back then. > > I'd say that Tkinter has substantially changed - with the introduction > of the 'ttk' themed widgets. I cover these in my tutorial > athttp://www.tkdocs.com > >>> Another book I've found very helpful for learning Tkinter is Programming >>> Python by Mark Lutz--a lot of coverage there of GUI development. >>> >> >> Another possible consideration when choosing a GUI to learn Python - >> will you want to print from within your GUI application? > > Excellent point. > > Many thanks to all who responded, especially for the reminder of the gui > sections in Programming Python (forgot I had that book!). I'll start by > going over that again, and we'll see how confident I feel afterwards. ;) > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > Is printing from GUI still a 'not-happening' thing with Tkinter ? I have just started learning it. -- |_|0|_| |_|_|0| |0|0|0| http://picasaweb.google.com/pradeepbpin -- http://mail.python.org/mailman/listinfo/python-list
Tkinter library reference
Do we have a standard reference library for Tkinter available? -- Pradeep -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter library reference
On Mon, May 31, 2010 at 2:46 PM, eb303 wrote: > On May 29, 3:11 pm, Pradeep B wrote: >> Do we have a standard reference library for Tkinter available? >> >> -- >> Pradeep > > Short answer: no, at least not a complete one for Tkinter itself. > > However, there is a complete reference for tcl/tk here: > http://www.tcl.tk/man/tcl8.5/ > Once you're used to converting tcl/tk's commands and options into > Tkinter classes and methods, it is the best one around. > > If you really need Python/Tkinter syntax, there are some good > documents here: > http://www.tkdocs.com/widgets/index.html > http://effbot.org/tkinterbook/ > But these are not complete or rather old. However, you can use them as > a starting point before diving into the tcl/tk reference above. > > HTH > - Eric - > -- > http://mail.python.org/mailman/listinfo/python-list > I think, generating it using the 'pydoc' seems to be much better. -pradeep -- |_|0|_| |_|_|0| |0|0|0| http://picasaweb.google.com/pradeepbpin -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Tkinter Programming by John Grayson
On Sat, May 29, 2010 at 7:33 PM, Kevin Walzer wrote: > Tkinter doesn't wrap native printing API's. There are a few extensions that > do it, but they are platform specific and not complete. > > The usual ways of printing are like this: > > 1. If you're outputting data from the text widget, write that to a temporary > text file and print via lpr. > > 2. If you're outputting data from the canvas, write that to a temporary > postscript file and print via lpr. > > This is on Unix/MacOS. Not sure what the equivalent API on Windows is. > > --Kevin > > -- > Kevin Walzer > Code by Kevin > http://www.codebykevin.com > -- > http://mail.python.org/mailman/listinfo/python-list > Thanx Kevin. Anybody can throw light on how to do the same in Windows ? -pradeep -- |_|0|_| |_|_|0| |0|0|0| http://picasaweb.google.com/pradeepbpin -- http://mail.python.org/mailman/listinfo/python-list
Backward compatible of Python 2 and Python 3
Hi, I want to make a program which works in both python 2.7 and python 3. Is it possible? For example python 2.7 have raw_input() to accept the input from command line whereas python 3.x method is input(). So I want to make sure the same program works in both the python versions. https://stackoverflow.com/questions/26174743/python-making-a-fast-port-scanner Regards Pradeep -- https://mail.python.org/mailman/listinfo/python-list
Multithreaded Python Mysql MAC Problems
Hi All, I wrote a multithreaded crawler program in Python 2.4 using Mysql 5.045 and MySqldb version as MySql-Python 1.2.2 on MAC OS 10.4.10 . The program strangely segfaults while it is running perfectly in Ubuntu and Windows as well. The gdb stack trace of program is below: LuLu:~/tempdownloads/crawl tspencer$ gdb python GNU gdb 6.1-20040303 (Apple version gdb-434) (Wed Nov 2 17:23:33 GMT 2005) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin"...Reading symbols for shared libraries .. done (gdb) run FinalCrawler.py Starting program: /Library/Frameworks/Python.framework/Versions/2.4/ bin/python FinalCrawler.py Reading symbols for shared libraries . done Program received signal SIGTRAP, Trace/breakpoint trap. 0x8fe01010 in __dyld__dyld_start () (gdb) bt #0 0x8fe01010 in __dyld__dyld_start () (gdb) info threads * 1 process 19802 local thread 0xf03 0x8fe01010 in __dyld__dyld_start () (gdb) continue Continuing. Reading symbols for shared libraries ... done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries .. done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries .. done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries ... done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done Reading symbols for shared libraries . done putting starting threads now putting putting putting putting putting putting putting putting putting 3 Now after Lock acquired 3 Now releasing lock Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_PROTECTION_FAILURE at address: 0x0090 [Switching to process 19802 thread 0x1703] _db_return_ (_line_=95, _sfunc_=0xb0283f3c, _sfile_=0xb0283f38, _slevel_=0xb0283f34) at dbug.c:828 828 state->framep = (char **) *state->framep; (gdb) The "putting" and number 3 are program's print statements. Can anyone please provide me with a insight into this problem and solution to it ? What might be the cause of this problem or how to go about further debugging it ? Thanks, Raja. -- http://mail.python.org/mailman/listinfo/python-list
