2,646 Posted Topics
Re: I think it works well. I changed the code to clip with [`np.clip()`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.clip.html) and plot the wave with [matplotlib](http://matplotlib.org/) in [ipython notebook](http://ipython.org/notebook.html) (This was done with python 2). See the plot below y_wavearray = np.array(wave,np.float64) y_clipped = np.clip(y_wavearray, -np.inf, 15000) x_points = len(wave) +1 x_values = np.arange(1,x_points) x_array = np.array(x_values,np.float64) … | |
Re: You could try and install pyparsing with the [windows installers](https://pypi.python.org/pypi/pyparsing/2.0.1) in pypi. | |
Re: I agree with vegaseat, try import tkinter print(tkinter) | |
Re: > There is a moment is every woman's life, when she wants to do something forbidden. Easy, the opposite is: *Some women never want to do anything forbidden*. Another solution was if int(menu) not in (1, 2): | |
Re: Perhaps replace `host` with `host.get()` in `lambda` . | |
Re: In linux, the [`file` command](https://en.wikipedia.org/wiki/File_%28command%29) can help you too. | |
![]() | Re: I suggest change your password for `foobarbazqux`, then uninstall wxpython, then change your password again. |
Re: I disapprove inflammatory debates in daniweb. I had one once with a knowledgeable programmer and some time later, he ceased to connect. I think he had too strong convictions and he wanted everybody to agree. ![]() | |
Re: Very good. I would have written `shutil.move(files, client_folder)`. Another solution is to create a sequence of files to move first def to_move(folder): """generate the files to move""" wd = os.getcwd() os.chdir(folder) try: for name in glob.glob('*.*'): if 'client_name' in str(name).lower(): yield os.path.join(folder, name) finally: os.chdir(wd) src_dir = r'd:\Desktop' L = … | |
Re: [QUOTE=longr59;1118842][CODE] #!/usr/bin/python import sys, os, time, shutil print time.ctime() path = "/home/richard/test/" files = os.listdir(path) files.sort() for f in files: src = path+f dst = "/home/richard/Desktop/test/" +f shutil.move(src, dst) print time.ctime() [/CODE][/QUOTE] Using functions from [url=http://www.daniweb.com/code/snippet239496.html]this code snippet[/url] and [url=http://www.daniweb.com/code/snippet254626.html]this code snippet[/url], you can also write [code=python] with WorkingDirectory("/home/richard"): tgz … | |
Re: Don't use `sleep()` in gui programs. Use a timer instead (method `after()` in tkinter). Run [this example](http://www.daniweb.com/software-development/python/code/384025/color-changing-window-demo-of-tkinter-after-timer-events) by PyTony to see how it works. | |
Re: If there is an open window, it means that the program is still running. Your question is a contradiction. What you can do is launch the turtle program from another program which exits immediately. For example here is a turtle program # progA.py from turtle import * angle = 5 … | |
Re: In python 2.6, you cannot use empty `{}` in format strings. Use `{0}` here. | |
Re: Try self.btnquit = button(calc_frame, "Quit", tk.destroy) self.btnquit.pack(side = LEFT) in method init, before `self.input = ...`. | |
Re: You can shorten the tests from graphics import * def patchdrawer(): win = GraphWin("Patch drawer", 100, 100) for x in range(0, 5): for y in range(1, 6): p1 = Point(x * 20, (y - 1) * 20) p2 = Point((x + 1) * 20, y * 20) rectangle = Rectangle(p1, … | |
Re: Check that **every** line in `msgs.txt` consists of 3 items separated by `#`. | |
Re: Here is an example of redirecting command `'python -V'` to a file with the subprocess module import subprocess with open('foo.out', 'wb') as ofh: process = subprocess.Popen(['python', '-V'], stdout = ofh, stderr = ofh) with open('foo.out', 'rb') as ifh: print(ifh.read()) | |
Re: I get something in my linux system with module pyudev >>> from pyudev import Context, Device >>> context = Context() >>> d = Device.from_device_file(context, '/dev/sda') >>> d.subsystem u'block' | |
This snippet prints a python list of strings in multicolumn format (similarly to linux `ls` command). It uses module prettytable, available in [pypi](https://pypi.python.org/pypi/PrettyTable). | |
Re: Useful tips: import funky print(funky) print(funky.__file__) This prints the path to the file where the module was found. Very useful when a module behaves in an strange way. | |
Re: You can use the Command class in [this code snippet](http://www.daniweb.com/software-development/python/code/257449/a-command-class-to-run-shell-commands). You would write com = Command("./vershion.sh").run() if com.failed: print(com.error) else: print(com.output) | |
This snippet is reserved for users of the KDE linux desktop. It adds a *service menu* to kde applications such as dolphin and konqueror, to launch an ipython dashboard in a directory in one click. More specifically, save the text of this snippet as a file `~/.kde/share/kde4/services/ServiceMenus/opennotebook.desktop` (create the directory … | |
Re: Partial does [currying](https://en.wikipedia.org/wiki/Currying): >>> from functools import partial >>> >>> def FOO(x, y, z): ... print((x, y, z)) ... >>> BAR = partial(FOO, "baz", "qux") >>> BAR(3.14) ('baz', 'qux', 3.14) BAR is the same function as FOO, but it takes only one argument (the last argument). The 2 first arguments have … | |
Re: Every gui problem has already been solved by vegaseat. Type `tkinter bargraph` in daniweb's search form and you'll find many examples, like [this one](http://www.daniweb.com/software-development/python/code/216816/draw-a-bar-graph-python), still fully working after 7 years ! | |
Re: Perhaps convert to dict first def main(args): f = open(args[1], 'w') inp = raw_input("Enter a Dict") # inp = {"a":1,"b":2} inp = django.utils.simplejson.loads(inp) assert isinstance(inp, dict) django.utils.simplejson.dumps(inp, f) | |
Re: The 4 letters words are nodes in a graph where adjacent nodes differ by one letter from the current node. Starting from the startword, you can do a depth first walk of the graph until you reach the endword. I posted a clue for depth first traversal [here](http://www.daniweb.com/software-development/python/threads/466930/adding-limit-to-web-crawler#post2033672) (replace urls … | |
Re: The obvious error is that the file argument in storbinary() must be an open file object instead of a string. Try with open(sourcepath, 'rb') as ifh: ftps.storbinary(outbound, ifh, 8192) | |
Re: BeautifulSoup 4.1.3 is out since August 20, 2012. It is compatible with python 2.6+ and python 3 ! | |
Re: It works for me and python 2.7. The output is A: array([[ 7, 3, -1, 2], [ 3, 8, 1, -4], [-1, 1, 4, -1], [ 2, -4, -1, 6]]) P: array([[ 1., 0., 0., 0.], [ 0., 1., 0., 0.], [ 0., 0., 1., 0.], [ 0., 0., 0., … | |
Re: At first glance, the error means that the symmetric difference is empty and your code does not handle the case. | |
Re: Your question is very opaque. I suspect it is already encrypted. Nevertheless, try this: try: input = raw_input except NameError: pass data = input("Please enter a 64 letters string: ") if len(data) == 64: print("SUCCESS") else: print("FAILURE") | |
Re: Your favorite search engine can help you with SQL syntax. Here is [an answer](http://www.tutorialspoint.com/sqlite/sqlite_using_autoincrement.htm) to your question. | |
Re: You must do a depth first traversal for this. The algorithm is very simple: suppose the urls line up at the post office with a number D written on their T-shirt, representing their depth. For every url, a web page is loaded and new urls discovered. The urls which have … | |
Re: **Not working** --> Exception thrown. Solve the issue described by the exception traceback ! Look [here](http://docs.python.org/3/library/urllib.request.html#module-urllib.request). | |
Re: It is not exactly the scheme. In python there is a [DB-API](http://www.python.org/dev/peps/pep-0249/), which many database modules, like sqlite3, try to implement. What this api says in short, si that the pseudo code looks like create a Connection object (using the db file name) create a Cursor object for this connection … | |
Re: [Here is a tutorial](http://lmgtfy.com/?q=python+minidom+tutorial) | |
Re: There are many things to change in your code. Solve the issues one by one with the help of the exception tracebacks printed by python. Here tre traceback is Traceback (most recent call last): File "./payrate.py", line 42, in <module> main() File "./payrate.py", line 7, in main payrate,hours=totalhours TypeError: 'float' … | |
Re: It is a very good idea to use a class instance to handle this. You can add a parameter `self` to all the functions and refactor the code like this: import random # ... think = ("Tänk på ett fyrsiffrigt tal med olika siffror") class Mastermind: def __init__(self): self.nya_gissningen = … | |
Re: Here is a math 'black box' that you can use from nzmath.gcd import extgcd from nzmath.matrix import Matrix def decrypt_key(cyph, uncyph, nletter): A = Matrix(2, 2, list(cyph)) D = A.determinant() u, v, d = extgcd(D, nletter) if d != 1: raise RuntimeError("Can not compute key matrix") B = (Matrix(2, 2, … | |
Re: Sending your code to the python interpreter yields File "<ipython-input-1-18413f1ea40a>", line 3 w=[l[0],l[1],l[2],l[3],l[4]) ^ SyntaxError: invalid syntax Please correct the syntax first and post code that python accepts to run. | |
Re: When fromlist is empty, `__import__('A.B.C')` returns module A, although it loads A, A.B and A.B.C and inserts them in sys.modules. Try mod = __import__("A.B.C", fromlist=["__name__"]) | |
Re: Improve woooee's idea by raising an exception class HangmanError(Exception): pass # ... fname="/path/to/file/images/0.gif" if os.path.isfile(fname): level=PhotoImage(file=fname) else: raise HangmanError(("No such file:", fname)) | |
Re: I suggest import pkgutil import os import sys L = list(sys.builtin_module_names) L += list(t[1] for t in pkgutil.iter_modules()) L = sorted(L) dst = os.path.expanduser("~/Desktop/modules.txt") with open(dst, "w") as ofh: ofh.write('\n'.join(L)) | |
Re: You can try hr, sc = divmod(counter, 3600) mn, sc = divmod(sc, 60) msg = '%d hours, %d minutes and %d seconds' % (hr, mn, sc) print(msg) | |
Re: I could not reproduce the bug on my system. Considering that you read the file with mode 'rb', perhaps you should write it in mode 'wb'. | |
Re: This forum is not an online homework service. We can help with issues in **your** implementation of the problem. Show some effort and post your attempts to find the bigrams. | |
![]() | Re: In a sequence `if...elif...elif...elif`, only the first *true* alternative is executed. Use a print to see what happens: def my_startswith(s1, s2): print((s1[0] == s2[0], s1[0] != s2[0], s2 == '', s1 == '' and s2 == '')) if s1[0] == s2[0]: return True elif s1[0] != s2[0]: return False elif … |
Re: define a `__repr__()` method. | |
You can teach your linux system that executable python files must be executed with /usr/bin/python. This allows you to write python scripts without the shebang line [icode]#!/usr/bin/env python[/icode]. This snippet shows you how to do it ! |
The End.