Re: TypeError: 'module object is not callable'
On Sep 4, 11:24 am, "Amit Khemka" <[EMAIL PROTECTED]> wrote: > On 9/4/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > Thanks guys. Changing to how Python does things has a lot of geting > > used to! > > Do any of you have any ideas on the best way to do the following > > problem: > > > Each loop I perform, I get a new list of Strings. > > I then want to print these lists as columns adjacent to each other > > starting with the first > > created list in the first column and last created list in the final > > column. > > > If you need any more information, just let me know! > > Cheers > > If I understand correctly what you may want is: > > >>> l = ['1', '2', '3', '4'] > > you can do: > > >>> print "\t".join(l) # lookup join method in stringmodule, > > assuming "\t" as the delimiter > > or, > > >>> for i in l: > > print i, '\t' , # note the trailing "," > > If this isnotwhat you want, post an example. > > Btw, Please post new issues in a separate thread. > > Cheers, > -- > > Amit Khemka > website:www.onyomo.com > wap-site:www.owap.in I think that is very similar to what I want to do. Say I had lists a = ["1" , "2", "3"] b = ["4", "5", "6"] c = ["7", "8", "9"] Stored in another list d = [a,b,c] I want the printed output from d to be of the form: 1 4 7 2 5 8 3 6 9 >From what I am aware, there is no table module to do this. The '\t' operator looks like it can allow this, I am playing with it at the moment, although going for my lunch break now! -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing lists in columns (was: TypeError: 'module object is not callable')
> But watch out if the lists aren't all the same length: zip won't pad out > any sequences, so it maynotbe exactly what is wanted here: > > >>> x = ['1', '2', '3'] > >>> y = ['4', '5'] > >>> for row in zip(x,y): > > print ', '.join(row) > > 1, 4 > 2, 5 > Unfortunately the lists will be of different sizes By the way I apologise for different questions within the same thread. When I have another question, I will make a new topic -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing lists in columns (was: TypeError: 'module object is not callable')
On Sep 4, 2:06 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > >> But watch out if the lists aren't all the same length: zip won't pad out > >> any sequences, so it maynotbe exactly what is wanted here: > > >> >>> x = ['1', '2', '3'] > >> >>> y = ['4', '5'] > >> >>> for row in zip(x,y): > > >> print ', '.join(row) > > >> 1, 4 > >> 2, 5 > > > Unfortunately the lists will be of different sizes > > In that case use: > > from itertools import repeat, chain, izip > def izip_longest(*args, **kwds): > fillvalue = kwds.get('fillvalue') > def sentinel(counter = ([fillvalue]*(len(args)-1)).pop): > yield counter() # yields the fillvalue, or raises IndexError > fillers = repeat(fillvalue) > iters = [chain(it, sentinel(), fillers) for it in args] > try: > for tup in izip(*iters): > yield tup > except IndexError: > pass > > x = ['1', '2', '3'] > y = ['4', '5'] > for row in izip_longest(x,y, fillvalue='*'): > print ', '.join(row) > > which gives: > > 1, 4 > 2, 5 > 3, * > > (izip_longest is in a future version of itertools, but for > now you have to define it yourself). Thanks guys I have a list of lists such as a = ["1" , "2"] b = ["4", "5", "6"] c = ["7",8", "9"] Stored in another list: d = [a,b,c] I know this makes me sound very stupid but how would I specify in the parameter the inner lists without having to write them all out such as: for row in izip_longest(d[0], d[1], d[2], fillvalue='*'): print ', '.join(row) i.e. How could I do the following if I didn't know how many list of lists I had. Sorry this sounds stupid and easy. Thankyou very much in advance as well, you are all very helpful indeed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing lists in columns
On Sep 4, 3:20 pm, Bruno Desthuilliers wrote: > [EMAIL PROTECTED] a écrit : > (snip) > > > Thanks guys > > > I have a list of lists such as > > a = ["1" , "2"] b = ["4", "5", "6"] c = ["7",8", "9"] > > Stored in another list: d = [a,b,c] > > > I know this makes me sound very stupid but how would I specify > > in the parameter the inner lists without having to write them all out > > such as: > > > for row in izip_longest(d[0], d[1], d[2], fillvalue='*'): > > print ', '.join(row) > > > i.e. How could I do the following if I didn't know how many list of > > lists I had. > > for row in izip_longest(*d, fillvalue='*'): > print ', '.join(row) > > HTH I thought that but when I tried it I recieved a "Syntax Error: Invalid Syntax" with a ^ pointing to fillvalue :S -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing lists in columns
On Sep 4, 3:20 pm, Bruno Desthuilliers wrote: > [EMAIL PROTECTED] a écrit : > (snip) > > > Thanks guys > > > I have a list of lists such as > > a = ["1" , "2"] b = ["4", "5", "6"] c = ["7",8", "9"] > > Stored in another list: d = [a,b,c] > > > I know this makes me sound very stupid but how would I specify > > in the parameter the inner lists without having to write them all out > > such as: > > > for row in izip_longest(d[0], d[1], d[2], fillvalue='*'): > > print ', '.join(row) > > > i.e. How could I do the following if I didn't know how many list of > > lists I had. > > for row in izip_longest(*d, fillvalue='*'): > print ', '.join(row) > > HTH I thought that, but when I tried it, I recieved a "Syntax error: invalid syntax" message with ^ pointing to the 'e' of fillvalue -- http://mail.python.org/mailman/listinfo/python-list
Re: Printing lists in columns
Thanks guys, I really appreciate it. I have never used google groups before and am so impressed with how helpful you all are. It is also lovely that none of you mock my little knowledge of Python but just want to improve it. I have another question in relation to the izip_longest function (I persume this should be within the same topic). Using this funciton, is there a way to manipulate it so that the columns can be formated tabular i.e. perhaps using something such as str(list).rjust(15) because currently the columns overlap depending on the strings lengths within each column/list of lists. i.e. my output is currently like: bo, daf, da pres, ppar, xppc magnjklep, *, dsa *, *, nbi But I want it justified, i.e: bo , daf, da pres , ppar, xppc magnjklep,*, dsa *,*, nbi I am struggling to understand how the izip_longest function works and thus don't really know how it could be manipulated to do the above. It would be much apprecited if somoene could also explain how izip_function works as I don't like adding code into my programs which I struggle to understand. Or perhaps I have to pad out the lists when storing the Strings? Any help would be much appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Accessing Module variables from another Module
Hi I am new to Python (I have come from a large background of Java) and wondered if someone could explain to me how I can access variables stored in my main module to other functions within other modules called from this module for example file: main.py from Storage import store from Initialise import init from ProcessSteps import process storeList = store() #Creates a object to store Step objects init() process() file: Initialise.py def init() .. storeList.addStep([a,b,c]) file: ProcessSteps.py def process() for step in storeList.stepList: etc I am currently just passing the variable in as a parameter but I thought with Python there would be a way to gain direct access to storeList within the modules called from the top main module? Cheers Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing Module variables from another Module
On Sep 5, 1:22 pm, Bruno Desthuilliers wrote: > [EMAIL PROTECTED] a écrit : > > > Hi > > > I am new to Python (I have come from a large background of Java) and > > wondered if someone could explain to me how I can access variables > > stored in my main module to other functions within other modules > > called > > from this module > > (snip code) > > I am currently just passing the variable in as a parameter > > And this is the RightThing(tm) to do. > > > but I thought with Python there would be a way to gain direct access > > to > > storeList within the modules called from the top main module? > > Yes : passing it as a param !-) > > For other modules to get direct access to main.storeList, you'd need > these modules to import main in these other modules, which would > introduce circular dependencies, which are something you usuallay don't > want. Also, and while it's ok to read imported modules attributes, it's > certainly not a good idea to mutate or rebind them IMHO, unless you're > ok with spaghetti code. Cheers Bruno, I just wanted to make sure I was being consistent with the "Python way of things" :) -- http://mail.python.org/mailman/listinfo/python-list
startswith( prefix[, start[, end]]) Query
Hi startswith( prefix[, start[, end]]) States: Return True if string starts with the prefix, otherwise return False. prefix can also be a tuple of suffixes to look for. However when I try and add a tuple of suffixes I get the following error: Type Error: expected a character buffer object For example: file = f.readlines() for line in file: if line.startswith(("abc","df")) CODE It would generate the above error To overcome this problem, I am currently just joining individual startswith methods i.e. if line.startswith("if") or line.startswith("df") but know there must be a way to define all my suffixes in one tuple. Thanks in advance -- http://mail.python.org/mailman/listinfo/python-list
Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute
Hi there I am fairly new to Python and have not really used regular expressions before (I think this might be needed for my query) and wondered if you could help I have a step class and store in a list step instances A step instance contains variables: name, startTime etc and startTime is stored as a string %H:%M:%S What I would like to do is to be able to sort this list of objects based on the startTime object so that the first item in the list is the object with the earliest Start time and last item is the object with the last Start time. I belive my key has to be = strpTime(step.sTime, "%H:%M:%S") But don't know how to create the comparison funciton. Any help on how I can perform this whole operation would be much appreciated. Thanks Chris -- http://mail.python.org/mailman/listinfo/python-list
Using a time duration to print out data where every 2 seconds is a pixel
Hi there, I wonder if any of you could tell me the best way to going about solving this little problem! I have a list of Step objects containing their start and finish times The steps are sorted so that they are in order of their step times The start and finish times are in string format of "%H:%S:%M" all on the same day I want to be able print out the Steps as a visual representation so that I can show 1. The order the steps started 2. The duration of the steps i.e. a print out such as: [a] [ b ] [ c ] so: [ stepName ] is the duration of the Step (i.e. 1 pixel for every 2 seconds it lasted) [ a ] started first so it is printed first, [ b ] started x seconds later so it is printed y pixels tabbed away form the side etc etc Any help would be much appreciated. Another related question is that I can't seem to do arithmetic when the variables are in String format of %H:%M:%S or converted to type struct_time i.e. > startPoint = strptime(step.sTime, "%H:%S:%M") > finishPoint = strptime(step.fTime, "%H:%S:%M") > duration = finishPoint - startPoint generates a error: Type error: unsupport operand types for: 'time.struct_time' and 'time.struct_time' trying to do time arithmetic when the times are stored in this format as strings also fails so any help regarding any of this would be muhc appreciated -- http://mail.python.org/mailman/listinfo/python-list
Re: Using a time duration to print out data where every 2 seconds is a pixel
Thanks however I am still having a problem using the time module for arithmetic My string times are of values such as 09:55:17 and I have code such as: >from time import * >startPoint = strptime(step.sTime, "%H:%S:%M") >finishPoint = strptime(step.fTime, "%H:%S:%M") >duration = mktime(startPoint) - mktime(finishPoint) but it generates the error >OverflowError: mktime argument out of range Cheers -- http://mail.python.org/mailman/listinfo/python-list
Re: Using a time duration to print out data where every 2 seconds is a pixel
On Sep 10, 3:57 pm, [EMAIL PROTECTED] wrote: > Thanks however I am still having a problem using the time module for > arithmetic > > My string times are of values such as 09:55:17 > > and I have code such as: > > >from time import * > >startPoint = strptime(step.sTime, "%H:%S:%M") > >finishPoint = strptime(step.fTime, "%H:%S:%M") > >duration = mktime(startPoint) - mktime(finishPoint) > > but it generates the error > > >OverflowError: mktime argument out of range > > Cheers Perhaps I need to import the datetime module? -- http://mail.python.org/mailman/listinfo/python-list
Re: Using a time duration to print out data where every 2 seconds is a pixel
On Sep 10, 6:39 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Mon, 10 Sep 2007 07:57:58 -0700, [EMAIL PROTECTED] declaimed the > following in comp.lang.python: > > > >from time import * > > >startPoint = strptime(step.sTime, "%H:%S:%M") > > >finishPoint = strptime(step.fTime, "%H:%S:%M") > > > >duration = mktime(startPoint) - mktime(finishPoint) > > Ignoring the mktime() error, shouldn't those be reversed -- end > times are larger than start times... > > > but it generates the error > > > >OverflowError: mktime argument out of range > > I suspect you will need to supply a full date... mktime() wants > calendar date/time values, not some HMS value that is relative to an > arbitrary zero. That is, if your data is in the form "9h 5m, 20s from > start of effort" you need to supply a dummy day representing "start of > effort" (midnight probably) > > Maybe look at the documentation for the datetime module -- in > particular timedelta() > > >>> from datetime import timedelta > >>> pStart = timedelta(hours=9, minutes=5, seconds=20) > >>> pEnd = timedelta(hours=13, minutes=21, seconds=5) > >>> dur = pEnd - pStart > >>> print dur.days, dur.seconds, dur.microseconds > > 0 15345 0 > -- > WulfraedDennis Lee Bieber KD6MOG > [EMAIL PROTECTED] [EMAIL PROTECTED] > HTTP://wlfraed.home.netcom.com/ > (Bestiaria Support Staff: [EMAIL PROTECTED]) > HTTP://www.bestiaria.com/ Thanks for all the help, I will have a look at my errors today. Can I also ask does anyone know how I could plot the "gannt chart" looking representation of my data without having to install something such as gnu plot. i.e. how would I simply work out how to move a space accross the screen every 2 seconds, if a Step lasted 45 seconds for example how would I represent that in terms of a print out with spaces? I hope that makes sense! -- http://mail.python.org/mailman/listinfo/python-list
Re: Using a time duration to print out data where every 2 seconds is a pixel
On Sep 11, 8:58 am, Tim Roberts <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > >Thanks however I am still having a problem using the time module for > >arithmetic > > >My string times are of values such as 09:55:17 > > >and I have code such as: > > >>from time import * > >>startPoint = strptime(step.sTime, "%H:%S:%M") > >>finishPoint = strptime(step.fTime, "%H:%S:%M") > > Your conversion strings cannot be correct. Sure, there are international > differences in rendering dates and times, but not even in Eastern > WhereTheHeckIsStan do they encode hours, then seconds, then minutes. > -- > Tim Roberts, [EMAIL PROTECTED] > Providenza & Boekelheide, Inc. Sorry I meant %H:%M:%S just wrote it wrong! Any advice on how to print out the duration though would be much appreciated. I think I have now got the time conversion problems sorted thanks to the help from google groups! -- http://mail.python.org/mailman/listinfo/python-list
Passing parameters at the command line (New Python User)
Hi there. I just wondered whether anyone could recommend the correct way I should be passing command line parameters into my program. I am currently using the following code: def main(argv = None): file1= "directory1" file2 = "directory2" if argv is None: args = sys.argv[1:] if len(args) == 0: Initialise.init(0) Process.processCon(file1, 0) Output.print() for i in range(len(args)): if args[i] == "-no": Initialise.init(0) Process.processCon(file2,1) Output.print() if args[i] == "-not": Initialise.init(1) Process1.process(stepStore, firstSteps) Output.print1() if __name__ == "__main__": main() Have I used bad syntax here so that a user can either run the program with commands: main.py main.py -no main.py -not If I also wanted an option file to be passed in at the command line for 'main.py' and 'main.py -no' what would be the best way to go about this? I have never used Python to pass in arguments at the command line so any help would be much appreciated. Cheers Chris -- http://mail.python.org/mailman/listinfo/python-list
WebBased Vector 2D Graphics
Hi there I currently have a Python program outputing to the command line, durations of 'completed Steps' and 'data items' in relation to time i.e. --jfh -kl//kl started after jfh finished % Ds //new data arrived at this point in time ---pl (1) //Details error with finsihed Step *kl // This step is now outputed but due to error with pl is cancelled (no duration) I am new to doing any web based development and don't have a clue where to start! I just wondered what is the best way to output this program to a web page graphically. I want to be able to represent these durations "-" as rectangles and as the program runs the page will refresh every 10 seconds, thus the boxes will expand with time until they have finished. New data will also be represented in boxes with a different colour. I believe some kind of script will have to be run which constantly updates the html page after x seconds which then causes the web page to refresh with the updated data. Is there any way this web programming can be done in python. Or perhaps I can use soemthing such as ajax? As mentioned previously, I have never done any web based development so don't really know what I'm talking about when trying to understand how I can go from this Python program output to producing some graphical output on a web page. Any help would be much appreciated Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: WebBased Vector 2D Graphics
On Oct 5, 11:43 am, Bjoern Schliessmann wrote: > [EMAIL PROTECTED] wrote: > > Is there any way this web programming can be done in python. > > Sure. Minimalistic approaches include using CGI > (http://docs.python.org/lib/module-cgi.html) > or using Apache with mod_python directly. There are also web > frameworks for Python, but I don't know much about them. > > > As mentioned previously, I have never done any web based > > development so don't really know what I'm talking about when > > trying to understand how I can go from this Python program output > > to producing some graphical output on a web page. > > The above approaches allow you to directly print to the web page. > I'm not sure how you could display constant progress there. Perhaps > much simpler with mod_python than with CGI. > > Regards, > > Björn > > -- > BOFH excuse #369: > > Virus transmitted from computer to sysadmins. Thanks Bjorn > The above approaches allow you to directly print to the web page. Would this mean I wouldn't be able to have any fancy graphics outputed such as the rectangles I mentioned before with different filled in colours? Cheers Chris -- http://mail.python.org/mailman/listinfo/python-list