3,386 Posted Topics
Re: import csv import time import datetime tempReadings = csv.reader(open('newdata3.csv','rb'),delimiter=',') for reading in tempReadings: print "got: %s" % reading (timestamp, format, temp) = reading print "timestamp: %s" % timestamp print "temp: %s" % temp Learn to push `[CODE]` before paste. I think you can use `itertools.islice` to read from 16th value … | |
Re: use chr function or struct module (docs.python.org/library/struct.html) | |
Re: Looks OK for me. | |
Re: I do not understand what you mean: [CODE]import Tkinter as tk def entry_down(event): frame.forget() frame.pack() entry.forget() entry.pack() entry.bind('<Return>', entry_up) print('Value: %s, from top to down' % entry.get()) def entry_up(event): frame.forget() frame.pack(side=tk.TOP) entry.bind('<Return>', entry_down) print('Value: %s, from down to top' % entry.get()) root = tk.Tk() frame = tk.Frame(root, bg= 'yellow', width=300, … | |
Re: You are passing sentence not words. You do not need to store append method zillion times to wrd. | |
Re: I do not see that your answers are wrong -- actually I do not see your answer. | |
Re: Please use code tags. That line worked for me: [CODE]>>> line='dhghgjj^Mfjjggjgjg^M' >>> line = line.replace("^M","") >>> line 'dhghgjjfjjggjgjg' >>> [/CODE] | |
Re: Not simple one liner (of course you can put everything in one line, but it becomes less readable), but I would do: [CODE]>>> d {'1': ['a'], '2': ['a', 'b', 'c']} >>> values = set(a for b in d.values() for a in b) >>> values set(['a', 'c', 'b']) >>> reverse_d = … | |
Re: [QUOTE=rslepoy;1701959]Hi, I'm using SAS regular expressions to read a large text file with numbers and characters, and may be up to 500 lines of text in the file. I would like to extract certain key words, specifically, weight quantaties and measures, i.e. kilos or lbs. Each line of text is … | |
Re: [QUOTE=skatamatic;1701498]Hah. Believe me, I tried the Google route. Pretty much ended up with either A)wiki pages with formulas containing unlabeled variables and fuzzy implementations or b)horribly messy, uncommented, and completely hard-coded spaghetti code. Good news though, I put it installed the PID module (as above with a little modification) on … | |
Re: Yes, you should have loop for line's start number and number running in one line. | |
| |
Re: Isn't it self not event? How could event have such method? | |
Re: I got same output as nbastec with his input file (except for the filename prompt/filename in report). This version is missing the handling of closing tag without opening tag. [CODE]class Stack(list): def push(self,x): self.append(x) def __iter__(self): while self: yield self.pop() @property def top(self): if self: return self[-1] class Queue(Stack): def … | |
Re: I do not know which value you have incorrect, but it is easier to say instead [CODE] print('text "%s" %s %s "%s" right' % (valuesgap*scalevalues, scaletip, GRAPHBOTTOM+(scalesygap*scalesvaluesygap), name))[/CODE] | |
Re: For example like [CODE]print 'Computer turn:' comp = random.choice([c for c in board if c.isdigit()]) [/CODE] Otherwise you can choose same as user chose (also you should check that user's input is in board). | |
Re: Maybe you should put something more in this loop: [CODE] for (x=1;x<=99;x++) { printf("%d%d",xfront,xback); } [/CODE] Nothing gives roman numbers here, xfront and xback do not change, only counter changes and it is not used for anything. I would make one function called roman_number taking int argument. I would then … | |
I post here the code for histogram using the turtle graphics module, which I posted long time ago in discussion thread. For more special graphs there exist other fancier options, but this tkinter based routine can function in most standard installations of Python. Example data.txt, like mentioned in module docstring: … | |
Re: POSIX systems access the information from utmp(x) file, here is guide about it: [url]http://80386.nl/unix/utmpx/[/url] | |
Re: Even after fixing the docstrings, could not get it to do other than generate one Deck, slicing did not work but dealing with Standard.Deck().popleft() in list comprehension got me some cards from deck. | |
Re: Use CODE tags and post your code. Notice that print allways adds newline at end if you do not suppress it. | |
Re: [CODE]self.__cards = self.__cards[26:] + self.__cards[:26][/CODE] | |
Re: One example of dealing with polynomials is my code snippet [url]http://www.daniweb.com/software-development/python/code/322922[/url] | |
Re: Be careful with capitalize method: [CODE]>>> 'notice: Tony Veijalainen posts to DaniWeb'.capitalize() 'Notice: tony veijalainen posts to daniweb' >>> 'notice: Tony Veijalainen posts to DaniWeb'.title() 'Notice: Tony Veijalainen Posts To Daniweb' [/CODE] | |
Re: Maybe you could setup user directories by os.path.expanduser. | |
Re: You could use Python ;) Also remember CODE tags. | |
Re: This boils to me as change of wording for 'mark bad' button to 'notify mods' button, which it has already become as mod request such notification for for example missing code tags, even wording of advice given for reporter is only talking of the breaking rules. Instead give list of … | |
Re: line 11 you use self.dir when you have parameter dir (which you did not save as instance variable). listdir is os.listdir? I would prefer to import os not from os import *. Base is also not used. | |
Re: You should put the action in function of secondscript and call it after importing it. Import runs the main script once, it has no effect if module is already loaded. | |
Re: Compare your approach with mine [url]www.daniweb.com/software-development/python/code/323868[/url] Shouldn't you return value in your recursive function, now you have only test print and return None? | |
Re: Your indention is off. Do you really want to hide built in function sum with your variable? Eval is unsafe from user input. | |
Re: Post (pseudo)code and we shoot it down/ concratulate you. | |
Re: I see some conflict between 'give me' and 'creative ideas' | |
Re: Looks for me like this parser accepts sign inside the number, multiple decimal points and e, does not deal with multiple negative sign correctly and accepts all garbage like it says in comment. Otherwise it would smell like ready answer to homework, which you should learn to resist (I know … | |
Re: This is very old thread, if you have questions or want critique of your code, start your own fresh thread. Also the OP of this thread wanted to produce single value for nth fibonacci number. That can be made for example like this: [CODE]def fib(n): prev = [0, 1] while … | |
Re: Compare with [url]www.daniweb.com/software-development/python/code/364647[/url] and reorganize your functions. problem is the if tests. | |
![]() | |
Re: One good traditional advice from WaltP. There is many approaches of course. Other good way to start is to start from different use cases, which you can use as base for tests. You implement functions/objects one by one and rerun unit tests to verify your progress and stop regressions showing … | |
Re: Looks for me that you are using global variables when you should use local so that the memory would only be recerved until need for values disapears. | |
Re: We like to read your ideas and comment about them. No guarantees, that we agree in our opinions here, however. So go ahead and give summary of your candidates. | |
Re: pascal is never called. | |
Re: Use loop, do not repeat code. [CODE]answers = [raw_input(q)+'\n' for q in open('questions.txt')] # save answers to file with open('answers.txt', 'w') as out: out.writelines(answers) if raw_input('Do you want to review your answers? ').lower() in ('yes', 'y'): with open('answers.txt') as inp: print inp.read() [/CODE] questions.txt [CODE=text]What is your name? What grade … | |
Re: This is not string, it is tuple. You can only write string to file. [CODE]myString = (line1,line2,line3,line4)[/CODE] | |
Re: [code]>>> f1 '>s1 MPPRRSIVEVKVLDVQKRRVPNKHYVYIIRVTWSSGATEAIYRRYSKFFDLQMQMLDKFP MEGGQKDPKQRIIPFLPGKILFRRSHIRDVAVKRLIPIDEYCKALIQLPPYISQCDEVLQ FFETRPEDLNPPKEEHIGKKKSGNDPTSVDPMVLEQYVVVADYQKQESSEISLSVGQVVD' >>> name, data = f1.split(None, 1) >>> print name[1:], ':', data.count('P') s1 : 15 [/code] | |
Re: [QUOTE=;][/QUOTE] Your code does not make sense to me. | |
Re: sql="""INSERT INTO PLAYERS(NAME) VALUES('%s')""" % newplayer | |
Re: As you have fixed length pattern it is not difficult to produce from generator expression without modules [code]>>> st = ''.join(''.join((a,b,c)) ... for a in string.ascii_uppercase ... for b in string.ascii_lowercase ... for c in string.digits) >>> len(st) 20280 >>> [/code] | |
Re: Simplistic but maybe fast enough way (somehow tested in my mobile): [code]def bitlength(n): for b in (shift for shift in itertools.count() if n>>shift < 1): return b-1 return 0 [/code] But actually newest Python versions have it builtin as [icode]bitlength[/icode] attribute of integers. You could use next function instead of … | |
Re: Ask specific question and post relevant, running piece of code or at least the code and clear explanation of error and what you wanted to accomplish with it. Use code tags, otherwise Python is imposible to read. | |
Re: I do not understand line 16 (myInfo does not exist and s trange strings syntax) or lines 4 and 5 (as you are not catching exceptions) |
The End.