2,646 Posted Topics
Re: I'm putting some comments in your code, in dive into python's way [code=python] def next_block(x): # [1] ... return p1, p2, p3, p4, p5, print (x) # [2] next_block("testing") # [3] p1, p2, p3, p4, p5 = next_block() # [4] """ [1] This function declares the argument x. It must … | |
Re: If this is your first python program, it's quite good. Congratulations ! Note however that you're using 8 times the same pair of statements [code=python] digit_letter() x1 = choice(dig_let) [/code] to create the list 'shuffled'. In a good program, you should not repeat 8 times the same sequence of statements. … | |
Re: Did you try [code=python] ItiaQPushButton.setText(self, "PROVA") [/code] ? | |
Re: In python, there is no difference between a variable in a for loop and a variable outside a for loop. I suggest that you forget all your batch and follow a good python tutorial step by step ! | |
Re: You could use a dictionary [code=python] class Country(object): def __init__(self, name): self.name = name def create_countries(): countriesDict = dict() print("Please enter the countries names (enter 'done' to exit the loop): ") while True: userInput = raw_input("country: ").strip() # or input if python 3.x if userInput: if userInput == "done": break … | |
![]() | Re: I can give you a hint [code=python] >>> from scipy.fftpack import fft [/code] and [url=http://www.scipy.org/SciPyPackages/Fftpack]a link[/url]. Now, all you have to do is to obtain an array of sampled data, call the function and get another array, the fft of the first. Next step: understand the meaning of the output. |
Re: If you have more than one computer at home, write a module 'home' containing at least 2 functions, [code=python] def download(src_path, dst_path, computer_name): ??? def upload(src_path, dst_path, computer_name): ??? [/code] which allow you to transfer files between computers at any time. When it works, think about new useful functions and … | |
Re: I can help you, but I can't write the code for you, so Step 1: build a python list containing all the lines of the file and print it. Step 2: remove the trailing \r\n at the end of each line Step 3: how can your program find the lines … | |
Re: Within the method, the name of your instance is external_variable. So you simply write [code=python] class second_class: def __init__(self,external_variable): print(external_variable.variable) # prints 0 [/code] | |
Re: In python 2. 6, have a look at the output of [code=python] bin(ord(character)) [/code] | |
This snippet defines a cachedProperty decorator. A cached property differs from a property in that it's value is only computed the first time that the property is accessed and then stored in the object's dict for later use. If the object's attribute is explicitely deleted, it will be computed again … | |
This snippet defines a function [icode]patfilter(pattern, rule, sequence)[/icode] which implements filtering a sequence of strings according to various criteria. The output is either a subsequence of strings, or a sequence of match objects. | |
Many threads in daniweb's python forum deal with menu based programs which run in a terminal. This snippet defines a handy class, MenuCrawler, to help writing such programs. Subclassing from this base classes and adding methods corresponding to a given set of menus allows one to build the menu-based application. … | |
This snippet defines a class which can group a collection of strings according to a given set of prefixes. Each string goes in the group of the longest prefix it contains. | |
This snippet allows your code to use the Mendeleiev's periodic table of elements. It defines a single function [icode]mendeleiev_table()[/icode] which returns the table as a python list of lists. | |
If you're not used to work with the standard module logging, this snippet will allow you to incorporate a logger in your application without effort. It gives you a starting point before you try to use more sophisticated features of the logging module. | |
This is a command line utility which lists the names of all functions defined in a python source file with a [icode]def <name>[/icode] statement | |
Re: I have a nice module for such tasks, which I call kernilis.path, which implements a useful 'path" class which methods access the functions of modules os, os.path and shutil. Just unzip the attached file and put the kernilis folder somewhere in your python path. Now the program looks like this … | |
Re: Another way to print the variables is [code=python] textfile.write("%(t)s %(omega1)s %(theta1)s\n" % locals()) [/code] | |
![]() | Re: [QUOTE=computerfreak97;966110]I got it working using tkSnack. Now does any one have any ideas on how to make a frequency analyzer?[/QUOTE] To analyse frequencies, you need to apply fast Fourier transform to a sampled signal. |
Re: I suggest that you write your own program to see what it does. | |
Re: An alternative is this [code=python] class LabelFoo(Exception): pass print '-'*20 try: for x1 in range(3): print 'x1 =', x1, for x2 in range(3): print 'x2 =', x2, for x3 in range(3): print 'x3 =', x3 if x3 == 1: raise LabelFoo except LabelFoo: pass [/code] | |
Re: [QUOTE=broberts_az;965365] Any suggestions about my crazy and annoying "are you sure" messages when you attempt to close the frame? I know that there should be a way to just wire this once and bind to the close frame button as well as the exit in the menu function?[/QUOTE] I suggest … | |
Re: hmm [code=python] import re pat = re.compile(r"((?:\\.|[^^])+)") data = r"Autocolli\^sion:No^Pack\^age:10DB15" print(pat.findall(data)) """ my output ---> ['Autocolli\\^sion:No', 'Pack\\^age:10DB15'] """ [/code] | |
Re: The module [icode]pygraphviz[/icode], which is python interface to graphviz, can generate graphs which can be converted to various formats. | |
Re: Mathematically, [icode]round(x, n)[/icode] is the number of the form [icode]integer * (10**(-n))[/icode] which is closest to x. For example round(2.12345678, 3) is 2.123. Python prints 2.1230000000000002 because it uses a binary representation internally and 2.123 has an infinite number of binary digits, but it means 2.123. For example if I … | |
Re: Replace [icode]=[/icode] (assignment operator) with [icode]==[/icode] (comparison operator). | |
Re: It only means that the function [icode]__init__[/icode] in the class temperature (which is called at instantiation) has an optional argument 'celsius'. Follow [url=http://www.diveintopython.org/power_of_introspection/optional_arguments.html]this link[/url] for the use of optional arguments to functions. | |
Re: You could also consider loading all the schools and children in memory and modify the database only when you know in which school each child goes (this can be done if you're able to compute the distance between a child and a school without the ST_DISTANCE function). Also, try to … | |
Re: On my home network, I transfer files using the pyro module. | |
Re: You could use [url=http://docs.python.org/library/cmath.html#cmath.phase]cmath.phase[/url] which returns the phase of a complex number in -pi, + pi. Note the equivalent [icode]math.atan2(y, x)[/icode] for the phase of the point (x, y). | |
Re: A standard design to avoid global variables is to define a class like this [code=python] class Competitions(object): def __init__(self): self. old_leader = 0 def read_file(self, database): ... def make_object(self, file1): ... etc if __name__ == "__main__": Competitions().main() [/code] | |
![]() | Re: "bad descriptor" refers to a file. To use readlines, you should open the file in "r" mode. Also another problem is that after the first call, the file position will be at the end of the file, so you can't call your function twice. A solution is to add a … |
![]() | Re: At first sight, it seems that you forget to call [icode]lower()[/icode]. ![]() |
Re: Here is a rather crude method, using subprocess [code=python] import subprocess as sp import time def browse(url, how_long): child = sp.Popen("firefox %s" % url, shell=True) time.sleep(how_long) child.terminate() browse("http://www.python.org", 3) [/code] However, on my system, this closes firefox only if it's not already running when the call to Popen happens. If … | |
Re: [QUOTE=willygstyle;957448]Hello, I'm pretty new to network programming as well. But I have managed to get some simple codes working such as a sniffer which can moniter all packets traveling in and out. I would assume that something like this would be useful so maybe read up as much as you … | |
Re: You can try this: [code=python] from collections import defaultdict match = defaultdict(int) for values in a: match[tuple(values[:3])] += 1 print(match) [/code] | |
Re: [url=http://docs.python.org/library/sys.html#module-sys]Look here[/url] :) | |
Re: API means "Application Programming Interface". When you write a piece of software, there may be a human interface (like a GUI) which allows a user to interact with your software and an API interface, which allows a [b]user program[/b] to interact with your software. The API is usually a collection … | |
Re: Just an idea, I fell on [url=http://davyd.livejournal.com/206645.html]this page[/url]. I think it should be possible to access the usb devices through HAL (sorry, I don't have enough time to investigate the idea now). | |
Re: Parsing often means "perform syntax analysis" on a program or a text. It means check if a text obeys given grammar rules and extract the corresponding information. For example, suppose that you define the rule that the structure of a question in english is [icode]auxiliary verb + subject + main … | |
Re: I suggest this [code=python] # Computes how much interest is earned on a given amount of principal. principal = float(raw_input('Enter principal: ')) interestRate = float(raw_input('Enter interest rate as a percent: ')) / 100 years = int(raw_input('Enter number of years: ')) totInterest = 0.0 for curYear in range(years): annualInterest = principal … | |
Re: Perhaps you could download a library for big numbers like [icode]gmpy[/icode] and compare the speeds with python's big ints ? | |
![]() | Re: To convert C arrays to numpy, you need to use numpy's C api. This is explained in numpy's documentation. There are a few functions to create a numpy array. The starting point is here [url]http://numpy.scipy.org/#docs[/url]. |
Re: There are many ways. You may use matplotlib or wxpython. I wrote a [code snippet](http://www.daniweb.com/software-development/python/code/217163/piecewise-linear-continuous-functions) which will give you immediately a graph. Try it ! :) | |
Re: You open a DOS shell (from the windows main menu, you should be able to open a command line (I don't use vista, so I don't know which terminology is used)). Then in this shell, you move to the Pmw folder that you downloaded, whith a command like [code] cd … | |
Re: It's very simple. [icode]test[0][/icode] is the inner array, so you can write [code=python] for num in test[0]: # do something with num [/code] | |
Re: A solution is to start a thread which runs the loop like this [code=python] from threading import Thread def my_function(): # put something here pass def my_loop(): while True: my_function() th = Thread(target= my_loop) th.start() do_something_else() # while the loop is running [/code] | |
Re: I think you should'nt call the method get_word. You should write [code=python] sorted_ent_list = entry_list.sort(key=entry_T.get_word) [/code] sort needs a reference to the function. | |
Re: Here is a solution which uses a class [icode]Record[/icode]. The problem with your implementation is that you repeat lines of code which look almost the same, which is a sure sign that the code must be improved. [code=python] class Record(object): def __init__(self, number, desc=""): self.number = number self.desc = desc … |
The End.