Re: Python Package documentation error
Hi Python Team, I think the statement "The __init__.py files are required to make Python treat directories containing the file as packages" is wrong in the documentation[1] because it is valid only for Python 2.x version not Python 3.x version. Even though it is good practice to have this file, it is not mandatory to have in Python 3x. to treat directories as packages. So I think we should correct it. [1] https://docs.python.org/3/tutorial/modules.html?highlight=packages#packages Thanks, Krishna On Fri, Sep 3, 2021 at 10:13 AM Krishna wrote: > Hi Python Team, > I think the statement "The __init__.py files are required to make Python > treat directories containing the file as packages" is wrong in the > documentation[1] because it is valid only for Python 2.x version not Python > 3.x version. > > Even though it is good practice to have this file, it is not mandatory to > have in Python 3x. to treat directories as packages. So I think we should > correct it. > > [1] > https://docs.python.org/3/tutorial/modules.html?highlight=packages#packages > > Thanks, > Krishna > -- https://mail.python.org/mailman/listinfo/python-list
Anyone has good understanding of how model base agents work in 2D array? --AIMA repository
Hi, I have started learning artificial intelligence and currently going through AIMA repository https://github.com/aimacode/aima-python but I am stucked at model base reflex agent implementation in the 2D environment. Does anyone have a good understanding of how model base agents work in 2D array? -- https://mail.python.org/mailman/listinfo/python-list
Understanding '?' in regular expressions
Can someone explain the below behavior please? >>> re1 = re.compile(r'(?:((?:1000|1010|1020))[ ]*?[\,]?[ ]*?){1,3}') >>> re.findall(re_obj,'1000,1020,1000') ['1000'] >>> re.findall(re_obj,'1000,1020, 1000') ['1020', '1000'] However when I use "[\,]??" instead of "[\,]?" as below, I see a different result >>> re2 = re.compile(r'(?:((?:1000|1010|1020))[ ]*?[\,]??[ ]*?){1,3}') >>> re.findall(re_obj,'1000,1020,1000') ['1000', '1020', '1000'] I am not able to understand what's causing the difference of behavior here, I am assuming it's not 'greediness' if "?" Thank you, Kishor -- http://mail.python.org/mailman/listinfo/python-list
python etl tool
can u please list out the etl tool which has been devloped in python and it is being used in market now? or just list me the etl tools developed in python? Thanks Krishnakumar.A -- http://mail.python.org/mailman/listinfo/python-list
etl tool!!!!!
Is there any efficient etl tool developed in python? -- http://mail.python.org/mailman/listinfo/python-list
Is there any module for automated testing in python?
Hi, Is there any module for automated testing in python? Pls help me frns.. From Gopi -- http://mail.python.org/mailman/listinfo/python-list
Why list comprehension faster than for loop?
Why list comprehension faster than for loop? -- http://mail.python.org/mailman/listinfo/python-list
can we change the variables with function
Hi can I change the variable in a function using the function suppose >>>def a(): x=20 can we change the variable using the function -- http://mail.python.org/mailman/listinfo/python-list
flattening list
Hi , Anyone can pls help me in flattening the list. if p is the my list which is defined below p=[1,[2,3,4],[5,6,],9,[[11,12]]] from the above how to get a list as [1,2,3,4,5,6,9,11,12] -- http://mail.python.org/mailman/listinfo/python-list
dictionary
When I give a dictionary with key and value in order how can get back iy in same order -- http://mail.python.org/mailman/listinfo/python-list
Does Abstract class , interfaces there in python ?
Hi , I want to know whether there is an abstract class and interfaces in python. If so how to implement it.. Pls help me on this. Thanks Gopi -- http://mail.python.org/mailman/listinfo/python-list
Re: Scalable python dict {'key_is_a_string': [count, some_val]}
On Fri, Feb 19, 2010 at 11:27 PM, Jonathan Gardner < jgard...@jonathangardner.net> wrote: > On Fri, Feb 19, 2010 at 10:36 PM, krishna > wrote: > > I have to manage a couple of dicts with huge dataset (larger than > > feasible with the memory on my system), it basically has a key which > > is a string (actually a tuple converted to a string) and a two item > > list as value, with one element in the list being a count related to > > the key. I have to at the end sort this dictionary by the count. > > > > The platform is linux. I am planning to implement it by setting a > > threshold beyond which I write the data into files (3 columns: 'key > > count some_val' ) and later merge those files (I plan to sort the > > individual files by the key column and walk through the files with one > > pointer per file and merge them; I would add up the counts when > > entries from two files match by key) and sorting using the 'sort' > > command. Thus the bottleneck is the 'sort' command. > > > > Any suggestions, comments? > > > > You should be using BDBs or even something like PostgreSQL. The > indexes there will give you the scalability you need. I doubt you will > be able to write anything that will select, update, insert or delete > data better than what BDBs and PostgreSQL can give you. > > -- > Jonathan Gardner > jgard...@jonathangardner.net Thank you. I tried BDB, it seems to get very very slow as you scale. Thank you, Krishna -- http://mail.python.org/mailman/listinfo/python-list
Scalable python dict {'key_is_a_string': [count, some_val]}
I have to manage a couple of dicts with huge dataset (larger than feasible with the memory on my system), it basically has a key which is a string (actually a tuple converted to a string) and a two item list as value, with one element in the list being a count related to the key. I have to at the end sort this dictionary by the count. The platform is linux. I am planning to implement it by setting a threshold beyond which I write the data into files (3 columns: 'key count some_val' ) and later merge those files (I plan to sort the individual files by the key column and walk through the files with one pointer per file and merge them; I would add up the counts when entries from two files match by key) and sorting using the 'sort' command. Thus the bottleneck is the 'sort' command. Any suggestions, comments? By the way, is there a linux command that does the merging part? Thanks, Krishna -- http://mail.python.org/mailman/listinfo/python-list
Re: zip a huge file into multiple small ones
Can i automate this process of uploading the zip file into a http server and getting the public url for that? On Mon, Sep 7, 2009 at 5:31 PM, Chris Rebert wrote: > On Mon, Sep 7, 2009 at 4:57 AM, Chris Withers > wrote: > > krishna chaitanya wrote: > >> > >> I am new to dealing with zip files in python. > >> I have a huge file which i need to zip and send as an attachment through > >> email. > >> My email restrictions are not allowing me to send it in one go. > >> Is there a way to split this file into multiple zip files, so that i can > >> mail them separately. > >> All the individual zip files should be linked. > >> I should be able to extract the original file by extracting the first of > >> the small zip files. > > > > You're using the wrong medium. Upload the file to an http server > somewhere > > and just include a link in the email... > > One such free service, among many others: > http://drop.io/ > > Cheers, > Chris > -- > http://blog.rebertia.com > -- http://mail.python.org/mailman/listinfo/python-list
zip a huge file into multiple small ones
I am new to dealing with zip files in python. I have a huge file which i need to zip and send as an attachment through email. My email restrictions are not allowing me to send it in one go. Is there a way to split this file into multiple zip files, so that i can mail them separately. All the individual zip files should be linked. I should be able to extract the original file by extracting the first of the small zip files. -- http://mail.python.org/mailman/listinfo/python-list
adding multiple new values to the same key in a dictionary
Hi, I want to be able to add multiple new values to a key in a dictionary. I have tried the following: sec_dict_clean= {88: [87, 89, 78, 98], 58: [57, 59, 48, 68], 69: [79], 95: [94, 96, 85]} for i in range(len(sec_dict_clean.values())): for j in range(len(sec_dict_clean.values()[i])): sec_dict_clean.setdefault(key,[]).append(blocks[sec_dict_clean.values()[i][j]].abundance) where blocks[...].abundance gives me a single value from an object, but this gives me the following: sec_dict_clean= {88: [87, 89, 78, 98], 58: [57, 59, 48, 68], 69: [79], 95: [94, 96, 85, 4, 12, 11, 6, 9, 12, 11, 7, 10, 10, 12, 9, 6, 12, 15, 9, 8, 12, 15, 12, 12]} instead I want each abundance (starts with 4, 12...) to be associated with each of the values so that it would look like this: sec_dict_clean= {88: ([87, 89, 78, 98], [4,12,11,6]), 58: ([57, 59, 48, 68], [9,12,11,7]), 69: ([79], [10])...} You can see there are several errors here (I have more things being appended than there are values in the dictionary), but I really just want to know how to add multiple values to the same key in a dictionary. Thanks for any help, Krishna -- http://mail.python.org/mailman/listinfo/python-list
Re: looping through values in a dictionary and appending to a list
Nevermind, got it. Sorry. >>> Krishna Pacifici 08/11/09 2:12 PM >>> Hi, I want to append the values of a dictionary to a list. I have a dictionary sec_dict_clean and I want to append the values to a list, but am having a hard time looping through the values in the dictionary. I have tried something like this: lista=[] for i in sec_dict_clean.values(): for j in sec_dict_clean.values()[i]: lista.append(sec_dict_clean.values()[i]) But I keep on getting an error: TypeError: list indices must be integers Any ideas on how to loop through values in a dictionary? Thanks, Krishna -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary help
Wow, thanks MRAB and Simon, you guys are good. I guess I will go ahead and ask the next question that has also stumped me for awhile now. So basically I need to loop through the values in the new dictionary and append attributes of a class object. Each of the values (and keys) represent a block in a grid with a specific location (e.g. 35 is the block in row 3 col 5) and each block is an object with several attributes associated with it. I want to call that block and append two separate attributes to the dictionary within that same key. So again it would look something like this: block 35 has 2 attributes, say a and b, a=2, b=5 block 37 has a=1, b=3 block 46 has a=3, b=8 the two attributes come from two different definitions within the class statement, def detections ... return a def abundance ... return b so I would want to append to key 36 those two attributes for each block so that the resulting dictionary item would look like this: a b {36:[35,37,46], [2,1,3], [5,3,8] ...} Any help with this would be greatly appreciated. And thank you so much for all of your help thus far, I'm still pretty new to python and am enjoying all of the flexibility associated with a scripting and programming language. Thanks again, Krishna >>> Simon Forman 08/11/09 12:15 PM >>> On Aug 11, 11:51 am, MRAB wrote: > Krishna Pacifici wrote: > > Thanks for the help. > > > Actually this is part of a much larger project, but I have unfortunately > > pigeon-holed myself into needing to do these things without a whole lot > > of flexibility. > > > To give a specific example I have the following dictionary where I need > > to remove values that are duplicated with other values and remove values > > that are duplicates of the keys, but still retain it as a dictionary. > > Each value is itself a class with many attributes that I need to call > > later on in the program, but I cannot have duplicates because it would > > mess up some estimation part of my model. > > > d = > > {36: [35, 37, 26, 46], 75: [74, 76, 65, 85], 21: [20, 22, 11, 31], 22: > > [21, 23, 12, 32], 26: [25, 27, 16, 36], 30: [20, 31, 40]} > > > So I want a new dictionary that would get rid of the duplicate values of > > 21, 22, 36 and 20 and give me back a dictionary that looked like this: > > > new_d= > > {36: [35, 37, 26, 46], 75: [74, 76, 65, 85], 21: [20, 11, 31], 22: [23, > > 12, 32], 26: [25, 27, 16], 30: [40]} > > > I understand that a dictionary may not be the best approach, but like I > > said I have sort of pigeon-holed myself by the way that I am simulating > > my data and the estimation model that I am using. Any suggestions or > > comments about the above problem would be greatly appreciated. > > >>> d = {36: [35, 37, 26, 46], 75: [74, 76, 65, 85], 21: [20, 22, 11, > 31], 22: [21, 23, 12, 32], 26: [25, 27, 16, 36], 30: [20, 31, 40]} > >>> new_d = {} > >>> seen = set(d.keys()) > >>> for k, v in d.items(): > ... new_d[k] = [x for x in v if x not in seen] > ... seen |= set(new_d[k]) > ... > >>> new_d > {36: [35, 37, 46], 75: [74, 76, 65, 85], 21: [20, 11, 31], 22: [23, 12, > 32], 26: [25, 27, 16], 30: [40]} Ha ha, MRAB beat me to it: d = { 36: [35, 37, 26, 46], 75: [74, 76, 65, 85], 21: [20, 22, 11, 31], 22: [21, 23, 12, 32], 26: [25, 27, 16, 36], 30: [20, 31, 40], } new_d = { # Given, and apparently incorrect. 36: [35, 37, 26, 46], # 26 is a key and should be gone. 75: [74, 76, 65, 85], 21: [20, 11, 31], 22: [23, 12, 32], 26: [25, 27, 16], 30: [40], } expected = { 36: [35, 37, 46], 75: [74, 76, 65, 85], 21: [20, 11, 31], 22: [23, 12, 32], 26: [25, 27, 16], 30: [40], } def removeDuplicates(D): ''' Remove values that are duplicated with other values and remove values that are duplicates of the keys. Assumes that values in the lists are already unique within each list. I.e. duplicates are only in the keys or in other lists. This function works "in place" on D, so it doesn't return anything. Caller must keep a reference to D. ''' seen = set(D) # Get a set of the keys. for key, values_list in D.iteritems(): # Filter out values that have already been seen. filtered_values = [ value for value in values_list if not value in seen ] # Remember newly seen values. seen.update(filtered_values) D[key] = filtered_values ## Example: ## ##>>> d == expected ##False ##>>> removeDuplicates(d) ##>>> d == expected ##True -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary help
Thanks for the help. Actually this is part of a much larger project, but I have unfortunately pigeon-holed myself into needing to do these things without a whole lot of flexibility. To give a specific example I have the following dictionary where I need to remove values that are duplicated with other values and remove values that are duplicates of the keys, but still retain it as a dictionary. Each value is itself a class with many attributes that I need to call later on in the program, but I cannot have duplicates because it would mess up some estimation part of my model. d = {36: [35, 37, 26, 46], 75: [74, 76, 65, 85], 21: [20, 22, 11, 31], 22: [21, 23, 12, 32], 26: [25, 27, 16, 36], 30: [20, 31, 40]} So I want a new dictionary that would get rid of the duplicate values of 21, 22, 36 and 20 and give me back a dictionary that looked like this: new_d= {36: [35, 37, 26, 46], 75: [74, 76, 65, 85], 21: [20, 11, 31], 22: [23, 12, 32], 26: [25, 27, 16], 30: [40]} I understand that a dictionary may not be the best approach, but like I said I have sort of pigeon-holed myself by the way that I am simulating my data and the estimation model that I am using. Any suggestions or comments about the above problem would be greatly appreciated. Thanks again, Krishna >>> Dave Angel 08/11/09 7:38 AM >>> Krishna Pacifici wrote: > Hi, > kind of a newbie here, but I have two questions that are probably pretty > simple. > > 1. I need to get rid of duplicate values that are associated with different > keys in a dictionary. For example I have the following code. > s={} > s[0]=[10,2,3] > s[10]=[22,23,24] > s[20]=[45,5] > s[30]=[2,4] > s[40]=[6,7,8] > > Now I want to be able to loop through the primary keys and get rid of > duplicates (both in keys and values) so that I would have either a new > dictionary or the same dictionary but with the following values: > > s[0]=[3] > s[10]=[22,23,24] > s[20]=[45,5] > s[30]=[2,4] > s[40]=[6,7,8] > > It doesn't matter which value gets removed as long as there is only one > remaining, so in this example it doesn't matter that 2 got removed from s[0] > or from s[30] as long as there is only one 2 in the dictionary. > > 2. I need to be able to loop over the values in the dictionary when there > are multiple values assigned to each key like above and assign new values to > those values. Taking the above example I would want to assign a new value so > that when you called s[0] it would equal [3,4] say if 4 was the new value. I > think this should be as simple as adding a value, but I kept on having > difficulty. > > Any suggestions would be greatly appreciated. > > Thank you very much, > Krishna > > > Sounds like homework. If it was for an unconstrained project, I'd design a different data structure, one that directly enforced the data constraints. So far, I can't imagine a useful reason for this particular set of constraints. Let's break the problems down. 1a) Do you know how to write a loop that visits all the keys of a dictionary? 1b) Do you know how to safely check if a particular key exists? e.g. if key in s: 1c) Do you know how to collect a set of values, so that when a duplicate is found, it can be recognized as such? 1d) Do you know how to remove an item from a list? 2a) Like 1a) 2b) Do you know how to append a value to the end of a list? Is s[key] a list? DaveA -- http://mail.python.org/mailman/listinfo/python-list
dictionary help
Hi, kind of a newbie here, but I have two questions that are probably pretty simple. 1. I need to get rid of duplicate values that are associated with different keys in a dictionary. For example I have the following code. s={} s[0]=[10,2,3] s[10]=[22,23,24] s[20]=[45,5] s[30]=[2,4] s[40]=[6,7,8] Now I want to be able to loop through the primary keys and get rid of duplicates (both in keys and values) so that I would have either a new dictionary or the same dictionary but with the following values: s[0]=[3] s[10]=[22,23,24] s[20]=[45,5] s[30]=[2,4] s[40]=[6,7,8] It doesn't matter which value gets removed as long as there is only one remaining, so in this example it doesn't matter that 2 got removed from s[0] or from s[30] as long as there is only one 2 in the dictionary. 2. I need to be able to loop over the values in the dictionary when there are multiple values assigned to each key like above and assign new values to those values. Taking the above example I would want to assign a new value so that when you called s[0] it would equal [3,4] say if 4 was the new value. I think this should be as simple as adding a value, but I kept on having difficulty. Any suggestions would be greatly appreciated. Thank you very much, Krishna -- http://mail.python.org/mailman/listinfo/python-list
How to convert he boolean values into integers
Hi Guys, I need to convert 1010100110 boolean value to some think like 2345, if its possible then post me your comment on this Advanced thanks for all Narayana perumal.G -- http://mail.python.org/mailman/listinfo/python-list
IDE
i need link of latest IDE of python(GUI) -- http://mail.python.org/mailman/listinfo/python-list
Access individual fields in csv using python
How do I access individual fields in csv using python? Please let me know ASAP as its real urgent for me. Thanks for your help Krishna -- http://mail.python.org/mailman/listinfo/python-list
importing part of a module without executing the rest
file1.py -- a = 20 from abc import * print "Should this be printed when 'a' is alone imported from this module" file2.py -- from file1 import a print a file2.py is used in a context where 'from abc import *' statement doesn't make sense but it can make sense of (and requires) 'a'. But it seems we can't import just a part of the module and expect the rest to not be executed. Executing python file2.py executes the 'from abc ...' and the print statement following it in file1.py. Can't I just import 'a' into this name scope without touching the rest of the statements in the module (file1 in this case). If so, what the rationale behind such logic in the module 'import' mechanism of python? Of course, the option of using if __name__ == '__main__' in file1.py for statements following 'a = 20' is not useful in my case as I need all statements in file1 to be exectued when imported by someone else (say file3.py) Don't I have any solution other than packaging those parts in file1.py (a = 20 and the rest of the statements) into different modules? -- http://mail.python.org/mailman/listinfo/python-list
data manipulation
I have a script that reads an excel file and and do manipulations on it. But, now, I have a text file that needs the same manipulation. I tried the same script, but it will not work, when I use command such as: workbook = xlrd.open_workbook('C:/trial.txt'), its giving me errors saying "expected BOF record". I was wondering how to work around this. Do I have to do some format conversion to accomplish this or am I missing something Thanks Krishna -- http://mail.python.org/mailman/listinfo/python-list
Re: Environment Variables
On Apr 25, 9:17 am, Mike Driscoll <[EMAIL PROTECTED]> wrote: > On Apr 25, 8:07 am, Krishna <[EMAIL PROTECTED]> wrote: > > > > > > > Environment variable set up is the most confusing part for me all the > > time. Please help me with the following questions: > > > When I install python in a new system, I will go to environment > > variables (system variables) and set "path" pointing to C:\Python25 > > and thats all I do. > > I type python from "cmd" window and its converting to python window > > for python execution. All fine up to this point. > > Now, I want to drag and drop python (.py) files to this window and > > execute it. My python files are located in different directories > > inside C: and outside C:. When I do that, I get errors and the file is > > not found and its not imported. ALso, inside the .py file, if I have a > > command to open a different file, it doesnt see that either. How do I > > overcome these basic difficulties in python. I wish I can open any > > file and work on that using python. > > > Thanks for your help! > > Krishna > > I'm pretty sure you can't do that in a command window. I tried it on > my Windows XP machine and all I get in my instance of IDLE is the path > to the file. It DOES work with PythonWin, which is the ActiveState > version of Python. The only difference is that it include the win32 > modules and has a more advanced editor. > > You can probably get this to work in other more advanced editors, like > WingIDE or PyDev too. > > Mike- Hide quoted text - > > - Show quoted text - So, how do I get the win32 module and what to do with that? Just install it? Thanks, Krishna -- http://mail.python.org/mailman/listinfo/python-list
Environment Variables
Environment variable set up is the most confusing part for me all the time. Please help me with the following questions: When I install python in a new system, I will go to environment variables (system variables) and set "path" pointing to C:\Python25 and thats all I do. I type python from "cmd" window and its converting to python window for python execution. All fine up to this point. Now, I want to drag and drop python (.py) files to this window and execute it. My python files are located in different directories inside C: and outside C:. When I do that, I get errors and the file is not found and its not imported. ALso, inside the .py file, if I have a command to open a different file, it doesnt see that either. How do I overcome these basic difficulties in python. I wish I can open any file and work on that using python. Thanks for your help! Krishna -- http://mail.python.org/mailman/listinfo/python-list
Re: Excel Manipulation using Python
On Apr 18, 11:36 am, Tim Golden <[EMAIL PROTECTED]> wrote: > Krishna wrote: > > I was trying to delete rows in an existing .xls file using python. How > > do I do that? I was using the following code, it seem to work if I > > type in python window, but if I save it in text editor and drage and > > drop the .py file, it doesnt work. What am I doing wrong here? Thanks > > for your help! > > > import win32com.client > > from time import sleep > > excel = win32com.client.Dispatch("Excel.Application") > > > def Extract(): > > excel.Visible = 0 > > workbook=excel.Workbooks.Open('C:\Trial.xls') > > > i=1 > > for n in range(1,10): > > excel.Rows(i).Select > > excel.Selection.Delete > > excel.Selection.Delete > > i=i+2 > > workbook.Save() > > print "saved" > > > excel.Quit() > > Several points worthy of note: > > 1) When you're dealing with Windows filenames, either make > the strings raw -- Open (r"c:\trial.txt") -- or use the other > slashes =-- Open ("c:/trial.xls"). > > 2) You're not actually calling the Select and Delete > methods, merely referencing them. Try .Delete () etc. > > 3) You're saving the workbook every time round the loop, > but perhaps you knew that. Might prompt you everytime > as you're overwriting, but again, maybe you knew... > > TJG- Hide quoted text - > > - Show quoted text - Cool, That worked! Thanks for your help TJG! -- http://mail.python.org/mailman/listinfo/python-list
Delete rows using xlrd?
I want to delete some rows (by creating a loop may be) using xlrd. Is this possible, if not how do I do that with python? Please help Thanks Krishna -- http://mail.python.org/mailman/listinfo/python-list
Excel Manipulation using Python
I was trying to delete rows in an existing .xls file using python. How do I do that? I was using the following code, it seem to work if I type in python window, but if I save it in text editor and drage and drop the .py file, it doesnt work. What am I doing wrong here? Thanks for your help! import win32com.client from time import sleep excel = win32com.client.Dispatch("Excel.Application") def Extract(): excel.Visible = 0 workbook=excel.Workbooks.Open('C:\Trial.xls') i=1 for n in range(1,10): excel.Rows(i).Select excel.Selection.Delete excel.Selection.Delete i=i+2 workbook.Save() print "saved" excel.Quit() -- http://mail.python.org/mailman/listinfo/python-list
Re: While executing the class definition which object is referenced by the first argument of the class method, Y r Object attributes not allowed as default arguments
On Mar 6, 5:04 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Thu, 06 Mar 2008 22:48:42 -0200, Krishna <[EMAIL PROTECTED]> > escribi�: > > > > >>>> class Test(object): > > ... def __init__(self): > > ... self.a= 2 > > ... def func(self, k = self.a): > > ... print k > > ... > > Traceback (most recent call last): > > File "", line 1, in ? > > File "", line 4, in Test > > NameError: name 'self' is not defined > > > In the 'definition of the class', what would the first argument 'self' > > in the methods evaluate to; when we have an object defined, it is > > bound to the object reference, but what happens while the class > > definition is executed, which I believe happens when the module > > containing the class definition is imported > > Function default arguments are evaluated when the function is defined > (when the class is defined, in this case) so "self" itself has not a > value. Try this instead: > > def func(self, k=None): > if k is None: > k = self.a > print k > > If None is an allowed argument, use a special marker instead: > > _marker=object() > ... > > def func(self, k=_marker): > if k is _marker: > k = self.a > ... > > -- > Gabriel Genellina Thanks for the reply. I am currently using the approach suggested by you. But, I am more interested in knowing about the first argument ('self'), what does it hold to allow the evaluation of the method, take the example you gave, 'self.a' as Rvalue inside the method, how and why is this allowed, when the same 'self.a' is not allowed as the default argument, considering the fact that I have already specified 'self' as first argument, only after whose evaluation, I believe would the next statement (k = self.a, in def func(self, k = self.a) ) gets evaluated Thanks, Krishna -- http://mail.python.org/mailman/listinfo/python-list
While executing the class definition which object is referenced by the first argument of the class method, Y r Object attributes not allowed as default arguments
>>> class Test(object): ... def __init__(self): ... self.a= 2 ... def func(self, k = self.a): ... print k ... Traceback (most recent call last): File "", line 1, in ? File "", line 4, in Test NameError: name 'self' is not defined >>> In the 'definition of the class', what would the first argument 'self' in the methods evaluate to; when we have an object defined, it is bound to the object reference, but what happens while the class definition is executed, which I believe happens when the module containing the class definition is imported Thanks, Kr -- http://mail.python.org/mailman/listinfo/python-list
Windows System Administration: State of the Art on Python?
I am a long-time user of Perl who comes to you in peace and is evaluating different scripting languages for use as a scripting platform for system administrators on the Windows platform. Perl already has many modules that allow sys admins and devolpers to do lots of things with the Windows OS, and I'm wondering what the state of the art is with Python and being able to control and administer a windows environment. In this regard, how does Python stand up against Perl? -- http://mail.python.org/mailman/listinfo/python-list
Re: copying files through Python
Hi this is the code which I wrote till now. It is giving permission denied error for sub folders of source directory. Does anyone have any idea what is going wrong import os import shutil def copytreetosinglefolder(src, dst): names = os.listdir(src) if (os.path.isdir(dst)==False): os.mkdir(dst) for name in names: srcname = os.path.join(src, name) try: shutil.copy2(srcname, dst) except (IOError, os.error), why: print "Can't copy %s to %s: %s" % (`srcname`, `dst`, str(why)) copytreetosinglefolder('c:\\src','d:\\dest') Tim Chase wrote: >> I am new to python. Infact started yesterday and feeling out of place. >> I need to write a program which would transfer files under one folder >> structure (there are sub folders) to single folder. Can anyone give me >> some idea like which library files or commands would be suitable for >> this file transfer task. I am sure its matter of few commands. It >> would be even more great if I could get some sample code with > > The shutils.copytree() command[1] will do what you describe > > Depending on your source, and if you want to make the dest writeable > (such as copying off a CD), you may also need to use os.walk() [2] > combined with os.chmod(filepath, stat.S_IWRITE) [3] > > -tkc > > [1] > http://docs.python.org/lib/module-shutil.html#l2h-2297 > > [2] > http://docs.python.org/lib/os-file-dir.html#l2h-2707 > > [3] > http://docs.python.org/lib/os-file-dir.html#l2h-2677 -- http://mail.python.org/mailman/listinfo/python-list
working of round()
Does round() always perfectly return the output expected or are there some artifacts which don't allow perfect functionality Using python 2.5: >>> round(12.234, 2) 12.23 >>> round(12.234, 3) 12.234 >>> round(12.234, 1) 12.199 >>> but was expecting 12.2 Also, for round(x,n), can't 'x' be an expression round(5.25/2, 2) was expecting 2.62 , but >>> round(5.25/2, 2) 2.6299 -- http://mail.python.org/mailman/listinfo/python-list
silent processing with python+modpython+cheetah
Hi, I have been working for some time developing web pages using python, modpython, cheetah. I find that this method has come inherent difficulties in it like if we want to generate a single page we have to write two separate files ( py & tmpl). Is there any other better way of doing things.? Also if we want to have partial processing of the pages, i.e, the value one chooses for a particular field determines the value to be entered for another field in the same page, how can it be done? Thanks, Sai krishna. -- http://mail.python.org/mailman/listinfo/python-list
Re: Screen capture on Linux
On 10/21/06, Paolo Pantaleo <[EMAIL PROTECTED]> wrote: > Hi, > > I need to capture a screen snapshot in Linux. PIL has a module Its defaultly provided in the 'actions' menu of the OS. > IageGrab, but in the free version it only works under Windows. Is > there any package to capture the screen on Linux? -- I love Freedom -- http://mail.python.org/mailman/listinfo/python-list
inserting into a file
I want to insert a string in a file after a particular line. I thought of using seek() function but on opening the file in append mode the seek value is undone. One crude idea i had was to read the file in a list and insert the string correspondingly. Is there any other way to do this? Please help... Sai krishna M -- I love Freedom -- http://mail.python.org/mailman/listinfo/python-list
Re: search/replace in Python (solved)
Leif K-Brooks wrote: > Oliver Andrich wrote: > > > For real-world use you'll want to URL encode and entityify the text: > > import cgi > import urllib > > def google_link(text): > text = text.group(1) > return '%s' % (cgi.escape(urllib.quote(text)), > cgi.escape(text)) > > re.sub(r"(.*)", google_link, "foo bar) Thanks a lot for your reply. I was able to solve it this way: text = re.sub( "([^<]*)", r'http://www.google.com/search?q=\1";>\1', text ) GVK -- http://mail.python.org/mailman/listinfo/python-list
search/replace in Python
Hello, I'm having some problems understanding Regexps in Python. I want to replace "PHRASE" with "http://www.google.com/search?q=PHRASE>PHRASE" in a block of text. How can I achieve this in Python? Sorry for the naive question but the documentation is really bad :-( Regards, GVK -- http://mail.python.org/mailman/listinfo/python-list