3,386 Posted Topics

Member Avatar for ccandillo

This is what I came up, values button is for testing. [CODE]#!/usr/bin/env python from Tkinter import * class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.sites = {} self.siteno = 0 self.master.title('Bulk FTP Updater') self.createShell() def createShell(self): frame = Frame(self) self.master_password, self.toggle_pass = StringVar(), IntVar() for widget in (Label(frame, text='Master Password:'), …

Member Avatar for ccandillo
0
288
Member Avatar for kafro

It is because of unorderedness, and the order in sets varies: [CODE]>>> s1 & s2 set([]) >>> s1 | s2 set(['a', 1, 'c', 'b', 3, 2]) >>> s1.symmetric_difference(s2) set(['a', 1, 2, 3, 'c', 'b']) >>> [/CODE]

Member Avatar for TrustyTony
0
112
Member Avatar for kiddo39

value of cursor is local, it can not work. Declare it global in beginning of the function or call save_this(cursor) from the function or put the code of save_this in end of SaveData. Change the functions name to save_data to follow Python naming convention.

Member Avatar for TrustyTony
0
1K
Member Avatar for 3FLryan

Maybe here is reason [CODE]import test print test """test is built in module: output: <module 'test' from 'J:\Python26\lib\test\__init__.py'>""" [/CODE]

Member Avatar for TrustyTony
0
453
Member Avatar for TrustyTony

This code is giving minimal change from real Python class to JavaMonster with every method having setter and getter not following the PEP8 naming but capitalizedWordsFormat. When instrunctor turns his head or if you put the code in your library, you can simply remove the setter/getter lines.

0
261
Member Avatar for pixelss

I think you need also need to upgrade the mind of your instructor, give him print of [url]http://dirtsimple.org/2004/12/python-is-not-java.html[/url] as present and ask him to stop acting against Python-do. [QUOTE]Getters and setters are evil. Evil, evil, I say! Python objects are not Java beans. Do not write getters and setters. This …

Member Avatar for SgtMe
0
906
Member Avatar for ljjfb
Member Avatar for prexioso

And which one you think is better name for variable list2 or identity_matrix? How about square or list1?

Member Avatar for prexioso
0
130
Member Avatar for pythonlearning

Maybe this helps: [CODE]import operator z = {'11': [0, 1], '3': [1, -2, 3], '4':[2, 3], '2':[3, -4, 5], '0':[4]} for key in z: int(key) sorted_z = sorted(((int(x),values) for x, values in z.iteritems()), key=operator.itemgetter(0)) print "z=", ''.join('%s %s\n' % pair for pair in sorted_z) [/CODE]

Member Avatar for pythonlearning
0
149
Member Avatar for txwooley

See code snippets for my anagram word finders, if you only need results and not want to spend time reinventing the wheel. Wooeee's code looks correct also, take your pick.

Member Avatar for txwooley
0
375
Member Avatar for xtra333

Gribouillis: Good point, the [B]assert at line 5[/B], instead of putting it in [B]if[/B], to spot the malformed tree!

Member Avatar for TrustyTony
0
309
Member Avatar for king_koder

And to keep coding Python 3 like, you can use in beginning of Python 2.7 programs: [CODE]from __future__ import print_function, division, generators try: input = raw_input # nobody use input, so lets overwrite it with Python3 style raw_input except: pass[/CODE] Then mostly your code runs both Python 2 and 3 …

Member Avatar for ultimatebuster
0
675
Member Avatar for 1991

You have at least much unimplemented stuff: [CODE]from random import shuffle class Room(object): empty = [] def __init__(self,name): self.name=str(name) self.hazard = self.empty def pits(self,antal): pit=1 while pit < antal: assert self.hazard == self.empty self.hazard = self.Pits ## undefined def bats(self,antal): bat=1 while bat < antal: assert self.hazard == self.empty self.hazard …

Member Avatar for 1991
0
7K
Member Avatar for yellowkaiq

This is little bit cleaner code than posted before: [CODE]from __future__ import print_function, division import time counter, timestr = 0, '' print(time.asctime()) t0 = time.time() try: while True: sectime, ff = divmod(counter,10) mintime, ss = divmod(sectime,60) hh, mm = divmod(mintime, 60) print(''.join('\b' for c in timestr), end='') timestr='%02i:%02i:%02i.%1s' % (hh, …

Member Avatar for TrustyTony
0
2K
Member Avatar for ralphcatech

See some object oriented books, I think ATM is standard example in one/some of them for use cases. Start simple, build function by function and test functionality of each separately.

Member Avatar for TrustyTony
-1
853
Member Avatar for longlongsilver

Assigning global values in objects attributes every time looks not ideal, like at line 13. You are using self.fuel, but fuel parameter is never used, and I do not understand parameter like that for move method. Fuel consumption per distance is not constant (inertia!)

Member Avatar for TrustyTony
0
158
Member Avatar for TrustyTony

Based on thread [url]http://www.daniweb.com/forums/thread323401.html[/url], I did this recursive version for comparision. Thanks for posters of the thread!

Member Avatar for TrustyTony
0
1K
Member Avatar for HoneyBadger

Here is my palindrome_ages generator: [CODE]>>> import itertools >>> for agediff,group in itertools.groupby(sorted([((b*10+a)-(a*10+b),(b*10+a),(a*10+b)) for a in range(6) for b in range(a+1,10)]), lambda x: x[0]): print agediff,list(group) 9 [(9, 10, 1), (9, 21, 12), (9, 32, 23), (9, 43, 34), (9, 54, 45), (9, 65, 56)] 18 [(18, 20, 2), (18, …

Member Avatar for gwmorris
0
288
Member Avatar for ekkanh

How about: [CODE]readfromfile = open(tname,"r") readfromtemp = open(tfname,"r") read1 = readfromfile.read() read2 = readfromtemp.read() self._list = [int(n) for n in read1.split(',')] self._cord = [n != 'False' for n in read2.split(',')] readfromfile.close() readfromtemp.close() [/CODE] woooee: But not with 'False' used without == [CODE] condition = 'False' if condition: print 'Condition True' …

Member Avatar for ekkanh
0
237
Member Avatar for LuckyX2

i am confused of your title as seem to be knowing the number of nodes without traversing. Looks like you are looking for connectedness.

Member Avatar for LuckyX2
0
166
Member Avatar for novice20
Member Avatar for sravi.pearl

check string method .replace(old, new) Like: [CODE]target = 's= The POST variable NM_xwTapCtl%24_img_Banner is vulnerable.,The POST variable NM_xwTapCtl%24scrollTop is vulnerable.' target = target.replace('The POST variable','').replace(' is vulnerable.','').replace(' ','') print target [/CODE]

Member Avatar for woooee
0
93
Member Avatar for sravi.pearl
Member Avatar for TrustyTony
0
103
Member Avatar for Austinstig

Something like this does the job, I think. [CODE]data = '''X, Y, Z 0.000234E+04, 0.000244E+03, 0.000234E+04 0.000244E+03, 0.000234E+04, 0.000238E+05 0.000238E+05, 0.000244E+03, 0.000234E+04''' numbers = data.splitlines() print numbers.pop(0) print '\n'.join(', '.join(str(float(value)) for value in numberline.split(',') ) for numberline in numbers) [/CODE]

Member Avatar for Austinstig
0
178
Member Avatar for auburner

cplusplus, this is Python forum! See Python tutorials for lists etc basic things. Experiment boldly interactively from Python command prompt. Build list, write it to file, read back in etc.

Member Avatar for TrustyTony
0
89
Member Avatar for arun_gan

We do not know context of your studies to know the purpose of this exersise. The purpose surely is not the correct output which can be directly produced with basic functions.

Member Avatar for TrustyTony
0
2K
Member Avatar for knan

For example like this. It is made more complicated the thing that you want to keep the integers as strings, so we can not append directly the int value: [CODE]x = ['abc','1','2','3','def','6','8','5','13','mcg','568','35469','6453'] key = x[0] mydict = dict() for data in x: try: # prove if int fails # we …

Member Avatar for TrustyTony
0
221
Member Avatar for kafro
Member Avatar for s0ur

Maybe this helps you to understand what happens with your code, you have the dict turned upside down, we turn it back. [CODE]>>> z = {'a': 1, 'a': 2, 'a': 3, 'b': 4, 'c': 5 } >>> z # only last saved value for 'a' is saved {'a': 3, 'c': …

Member Avatar for s0ur
0
190
Member Avatar for marboleon

Line 6 looks strange. Use attributes not global variables. Looks like frame would be global variable. Print also value of frame on line 17.

Member Avatar for marboleon
0
182
Member Avatar for ekkanh

Here little cleaner form for slate's code (which need fi.close() in the end of for) Actually the names.txt would be better to open same way, but I think it is OK, as garbage collection surely gets it from inside the stripping generator expression (i.e. it will be automatically freed also). …

Member Avatar for Gribouillis
0
105
Member Avatar for novice20

By google knows method having not used the module myself, this looks promissing: [url]http://www.saltycrane.com/blog/2009/09/python-optparse-example/[/url]

Member Avatar for Gribouillis
0
63
Member Avatar for Krstevski

Can not say I understood much, especially for reason of doing all this stuff, but here is what I cathered from program that I understood. For others like me. [CODE]import urllib2 from xml.dom.minidom import parse def google_suggest(word): """Google Suggest function google_suggest(word) returns list of unicode strings of suggestions""" page = …

Member Avatar for TrustyTony
0
657
Member Avatar for parallel91

[QUOTE=king_koder;1380231]Try replacing the code in line 26 with: [CODE=python]if word not in stopWordsList: words.get(word, 0) + 1[/CODE][/QUOTE] You mean: [CODE=python]if word not in stopWordsList: words[word] = words.get(word, 0) + 1[/CODE]

Member Avatar for king_koder
0
281
Member Avatar for HoneyBadger

replace line 1-2 with [code]with open('file') as fin: for line in fin:[/code]

Member Avatar for TrustyTony
0
93
Member Avatar for Sykee

x_coordinate and y_coordinate does exactly same thing, remove one and call_it get_coordinate (replacing all x, with neutral name, say coord) and use instead of line 8-9 [CODE]x, y = get_coordinate(), get_coordinate()[/CODE] Then pass x,y also to function at line 53.

Member Avatar for TrustyTony
0
161
Member Avatar for king_koder

Move slate's line 15 to else part of try except. Maybe that fixes the issue of maximum (untested)

Member Avatar for king_koder
0
404
Member Avatar for HoneyBadger

... Or from second form replace print with return [code] return list1[/code]

Member Avatar for ultimatebuster
0
91
Member Avatar for marboleon
Member Avatar for TrustyTony
0
181
Member Avatar for fraky

Or you might do something like (with statement need version 2.7 or later, otherwise change it to nested withs) [CODE]#! /usr/bin/python from __future__ import print_function import sys import time def produce_key(line): return '%s%04s%04s' % tuple(line.split(None, 3)[:3]) t0 = time.time() with open(sys.argv[1]) as firstfile, open(sys.argv[2]) as secondfile: hashedfile = {produce_key(line) : …

Member Avatar for TrustyTony
0
144
Member Avatar for HoneyBadger

Now your function is basically doing nothing right. Start from beginning and test and add functionality. Step one: make this print string word, if string forbid is in word [code] forbid = 'e' word = 'test' if # your code[/code]

Member Avatar for TrustyTony
0
189
Member Avatar for James0l9l

Maybe computer is like me and don't find its way through. Do you know that you can use more than one letter for variable names? Also you can write comments by # and comment. First line of function should have comment in triple quotes and explanation of what function is …

Member Avatar for woooee
0
102
Member Avatar for pacers10

This code would be extremely helpfull starting point if you can handle it. You would probably need to do some read up on itertools and list comprehensions before you continue: [CODE]from itertools import groupby def isletter(c): return c.isalpha() sentence = "First, think about how this program interacts with the user. …

Member Avatar for woooee
0
135
Member Avatar for Brickmack

Maybe this is too early, but generally the way after you become more familiar with the functions, you can start to use generator expressions, which I love very much and looks often (but not always) more readable to me. In my own idioms, giving maybe some ideas for future: [CODE] …

Member Avatar for richieking
0
955
Member Avatar for Finki

Here one non-re way also: [CODE]from itertools import groupby import string text = """Just a simple text. We can count the words! Why do words have to end? Every now and then a blank line. Perhaps it will snow! Wow, another blank line for the count. That should do it …

Member Avatar for TrustyTony
0
2K
Member Avatar for Finki

Here is solution without using split and lists only strings and itertools generators (as this is clearly homework you should show some effort of solving yourself). I bet this is not what your instructor is expecting for solution! [CODE]from __future__ import print_function from itertools import groupby try: input = raw_input …

Member Avatar for Finki
0
100
Member Avatar for G-nerd

I am still likely to do this kind of thing by building a new tuple (I have heart tuple is faster to construct than list) of words like this instead of deleting. I do not know how much slower it would be: [CODE]def bawdlerize(s,w): return tuple(word for word in s …

Member Avatar for slate
0
281
Member Avatar for TrustyTony

Here some experiments to pretty print polynomials with help of vegaseat's tip of wx.lib.fancytext.

Member Avatar for Gribouillis
1
764
Member Avatar for ekkanh

Still it is ill adviced to use tabs in writing code, use autoindenting editor with whitespace tabs. Those have function 'untabbify', use that and correct the indention with whitespace tabs.

Member Avatar for slate
0
7K
Member Avatar for jrp370

Could you avoid using built in function sum as your variable you end up confusing other and even yourself later with some 'interesting' bugs in your program. If you can not really find other name for the variable, there is standard way to avoid it: use sum_ instead of sum …

Member Avatar for group256
0
97

The End.