3,386 Posted Topics
Re: 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:'), … | |
Re: 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] | |
Re: 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. | |
Re: 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] | |
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. | |
Re: 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 … | |
Re: send them three at once maybe? Now looks like you send whole file to each. | |
Re: And which one you think is better name for variable list2 or identity_matrix? How about square or list1? | |
Re: 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] | |
Re: 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. | |
Re: Gribouillis: Good point, the [B]assert at line 5[/B], instead of putting it in [B]if[/B], to spot the malformed tree! | |
Re: 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 … | |
Re: 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 … | |
Re: 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, … | |
Re: 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. | |
Re: 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!) | |
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! | |
Re: 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, … | |
Re: 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' … | |
Re: i am confused of your title as seem to be knowing the number of nodes without traversing. Looks like you are looking for connectedness. | |
| |
Re: 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] | |
Re: Use [CODE]separator.join(sequence_of_string_values)[/CODE] | |
Re: 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] | |
Re: 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. | |
Re: 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. | |
Re: 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 … | |
Re: Do not use identity check [B]is[/B] use [B]==[/B]. | |
Re: 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': … | |
Re: Line 6 looks strange. Use attributes not global variables. Looks like frame would be global variable. Print also value of frame on line 17. | |
Re: 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). … | |
Re: 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] | |
Re: 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 = … | |
Re: [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] | |
Re: replace line 1-2 with [code]with open('file') as fin: for line in fin:[/code] | |
Re: 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. | |
Re: Move slate's line 15 to else part of try except. Maybe that fixes the issue of maximum (untested) | |
Re: ... Or from second form replace print with return [code] return list1[/code] | |
Re: Variable should not be needed, but you use the function ie put after it () | |
Re: 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) : … | |
Re: 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] | |
Re: 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 … | |
Re: 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. … | |
Re: 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] … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Here some experiments to pretty print polynomials with help of vegaseat's tip of wx.lib.fancytext. | |
Re: 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. | |
Re: 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 … |
The End.