3,386 Posted Topics

Member Avatar for StefanieZY

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 …

Member Avatar for TrustyTony
0
365
Member Avatar for mwjones
Member Avatar for woooee
0
229
Member Avatar for kalookakoo
Member Avatar for 1337RAM1337

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, …

Member Avatar for 1337RAM1337
0
325
Member Avatar for THEPalletizer

You are passing sentence not words. You do not need to store append method zillion times to wrd.

Member Avatar for THEPalletizer
0
399
Member Avatar for Raaz_mystery
Member Avatar for TrustyTony
0
98
Member Avatar for bellarc

Please use code tags. That line worked for me: [CODE]>>> line='dhghgjj^Mfjjggjgjg^M' >>> line = line.replace("^M","") >>> line 'dhghgjjfjjggjgjg' >>> [/CODE]

Member Avatar for woooee
0
333
Member Avatar for slash16

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 = …

Member Avatar for TrustyTony
1
2K
Member Avatar for rslepoy

[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 …

Member Avatar for rslepoy
0
334
Member Avatar for skatamatic

[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 …

Member Avatar for skatamatic
0
2K
Member Avatar for AdampskiB

Yes, you should have loop for line's start number and number running in one line.

Member Avatar for techie1991
0
167
Member Avatar for daniel5126
Member Avatar for stefh
Member Avatar for asong

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 …

Member Avatar for asong
0
236
Member Avatar for mr.ch

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]

Member Avatar for mr.ch
0
107
Member Avatar for hovestar

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).

Member Avatar for TrustyTony
0
8K
Member Avatar for terence193

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 …

Member Avatar for terence193
0
228
Member Avatar for TrustyTony

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: …

0
2K
Member Avatar for coding101

POSIX systems access the information from utmp(x) file, here is guide about it: [url]http://80386.nl/unix/utmpx/[/url]

Member Avatar for TrustyTony
0
45
Member Avatar for lrh9

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.

Member Avatar for lrh9
0
1K
Member Avatar for AdampskiB

Use CODE tags and post your code. Notice that print allways adds newline at end if you do not suppress it.

Member Avatar for AdampskiB
0
120
Member Avatar for s00pahFr0g
Member Avatar for TrustyTony
0
312
Member Avatar for Flames91

One example of dealing with polynomials is my code snippet [url]http://www.daniweb.com/software-development/python/code/322922[/url]

Member Avatar for TrustyTony
0
517
Member Avatar for obito

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]

Member Avatar for TrustyTony
0
112
Member Avatar for giancan
Member Avatar for Blazko89
Member Avatar for ~s.o.s~

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 …

Member Avatar for Dani
2
358
Member Avatar for metalix

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.

Member Avatar for metalix
0
279
Member Avatar for giancan

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.

Member Avatar for giancan
0
189
Member Avatar for RM@Bowdoin

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?

Member Avatar for Gribouillis
0
2K
Member Avatar for my_py

Your indention is off. Do you really want to hide built in function sum with your variable? Eval is unsafe from user input.

Member Avatar for my_py
0
175
Member Avatar for C@un5el@r
Member Avatar for technoSE
Member Avatar for TrustyTony
0
188
Member Avatar for The 42nd

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 …

Member Avatar for TrustyTony
0
2K
Member Avatar for MakingMoney

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 …

Member Avatar for TrustyTony
0
2K
Member Avatar for Cheese7

Compare with [url]www.daniweb.com/software-development/python/code/364647[/url] and reorganize your functions. problem is the if tests.

Member Avatar for Cheese7
0
155
Member Avatar for draven07
Member Avatar for tunde011

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 …

Member Avatar for TrustyTony
0
139
Member Avatar for Morten Brendefu

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.

Member Avatar for Morten Brendefu
0
141
Member Avatar for Kavatae

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.

Member Avatar for stakeMyHeart
0
1K
Member Avatar for ERINY
Member Avatar for Jetster3220

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 …

Member Avatar for woooee
0
320
Member Avatar for bigredaltoid

This is not string, it is tuple. You can only write string to file. [CODE]myString = (line1,line2,line3,line4)[/CODE]

Member Avatar for bigredaltoid
0
166
Member Avatar for sainitin

[code]>>> f1 '>s1 MPPRRSIVEVKVLDVQKRRVPNKHYVYIIRVTWSSGATEAIYRRYSKFFDLQMQMLDKFP MEGGQKDPKQRIIPFLPGKILFRRSHIRDVAVKRLIPIDEYCKALIQLPPYISQCDEVLQ FFETRPEDLNPPKEEHIGKKKSGNDPTSVDPMVLEQYVVVADYQKQESSEISLSVGQVVD' >>> name, data = f1.split(None, 1) >>> print name[1:], ':', data.count('P') s1 : 15 [/code]

Member Avatar for woooee
0
193
Member Avatar for sofia85
Member Avatar for Zeref
Member Avatar for debasishgang7

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]

Member Avatar for debasishgang7
0
261
Member Avatar for python12345

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 …

Member Avatar for Rick345
0
12K
Member Avatar for MRoman

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.

Member Avatar for MRoman
0
199
Member Avatar for just_starting

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)

Member Avatar for just_starting
0
189

The End.