2,646 Posted Topics

Member Avatar for TrustyTony

It is nice, but I think echo() should take a single argument and return a single argument like this [code=python] def echo(arg): print(arg) return arg [/code] Having a unary function allows use with imap() for example [code=python] from itertools import imap s = sum(imap(echo, (x * x for x in …

Member Avatar for Gribouillis
1
1K
Member Avatar for floatingshed
Member Avatar for floatingshed
0
73
Member Avatar for ozzyx123

This is Cython code. It seems to be a version of Prahaai's pure python code here [url]http://www.daniweb.com/software-development/python/threads/152831[/url]. See if the pure python version works. Also notice that a pyPdf module exists here [url]http://pybrary.net/pyPdf/[/url] . Here is an example code to count the pages in a pdf file with python 2 …

Member Avatar for TrustyTony
0
881
Member Avatar for Vkitor

It looks easy, replace all the v1, v2, v3 .. variables with arrays v[0], v[1], v[2], something like [code=python] import tkinter as tk from functools import partial def klik(n): button[n].config(image=s[n]) root = tk.Tk() frame1 = tk.Frame(root) frame1.pack(side=tk.TOP, fill=tk.X) karirano = tk.PhotoImage(file="kari.GIF") s = list(tk.PhotoImage(file="%d.GIF" % (i+1)) for i in range(4)) …

Member Avatar for Gribouillis
0
23K
Member Avatar for straylight

Your pseudo code is cryptic. In the 2 first ifs, row seems to be an integer, then in the else part it's an iterable, and you don't say what 'the first in row' and 'the last in row mean'. Could you give an example of what the row variable contains …

Member Avatar for woooee
0
169
Member Avatar for KatseasSAvvas

When one of c or d is not zero, the equation has an infinite number of solutions. In fact the solutions of [icode]x * c + y * d = f[/icode] are [code=text] x = (f * c - z * d)/(c**2 + d**2) y = (f * d + …

Member Avatar for TrustyTony
0
284
Member Avatar for ihatehippies
Member Avatar for Jetster3220

You could use the format method [code=python] def __str__(self): return "Dog named '{0}', aged {1} (human age {2} years)".format( self.name, self.age, self.getPersonAge()) [/code] Also the class name should be capitalized (Dog) to conform python's tradition.

Member Avatar for Gribouillis
0
232
Member Avatar for breatheasier

[QUOTE=xopenex;1766164]hello, how would i change the code here, to have python create variables that i can call later, instead of files?[/QUOTE] The best way is to create a dictionary instead of variables [code=python] from pprint import pprint dic = dict() for a in range(50): if a % 10 in (4, …

Member Avatar for xopenex
0
5K
Member Avatar for pwolf

Try [code=python] return "".join((seqA, '\n', a, '\n', seqB, '\n', 'Score: %d' % sum(c))) [/code] edit: don't use tabs to indent python code, use 4 spaces.

Member Avatar for TrustyTony
0
1K
Member Avatar for Thisisnotanid

No it's not possible to have assignments in if conditions. The reason is that assignment is a statement and cannot be part of an expression (the same applies to += -=, etc), while the 'if' statement expects an expression. The potential problem with your code above is that it evaluates …

Member Avatar for Thisisnotanid
0
181
Member Avatar for Thropian
Member Avatar for Gribouillis
0
161
Member Avatar for DanWebb3148

Use the builtin function bytearray() [code=python] >>> L = bytearray(10) >>> L bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') >>> L[3] = 'a' >>> L bytearray(b'\x00\x00\x00a\x00\x00\x00\x00\x00\x00') [/code] edit: sorry, that was not exacly your question, but perhaps you can use a block of 8 consecutive bytes for your purpose.

Member Avatar for DanWebb3148
0
973
Member Avatar for vlady

Replace line 18 with [icode]lpre.append(subject.name)[/icode]. You can also replace line 19 with [icode]return ", ".join(lpre)[/icode].

Member Avatar for Gribouillis
0
98
Member Avatar for hughesadam_87

I think you must specify a length for the strings, otherwise the length defaults to zero. [code=python] import numpy timefile_dtype=numpy.dtype([ ('filename', file), ('year', int), ('month', str, 25), ('day', int), ('time', str, 25), ('int_time', int), ('unit', str, 25), ('avg', int), ('boxcar', int), ]) a = numpy.zeros((1,), dtype=timefile_dtype) x = a[0] x['filename'] …

Member Avatar for hughesadam_87
0
1K
Member Avatar for fatalaccidents

It's a matter of personal taste. C is reasonably easy to learn, and it's a whole culture which will help you understand 50 years of programming and OS development.

Member Avatar for moroccanplaya
0
363
Member Avatar for vlady

It's a design issue. Here is my son's school report [code=test] FRANCAIS Mrs xxx 17,0 , 13,0 , 16,0 , 19,0 , 10,5 , 18,0 LATIN Mrs xxx 5,0 ANGLAIS LV1 Miss xxx 12,5 , 18,0 ESPAGNOL LV1 Mrs xxx 12,5 , 8,0 , 12,0 HIST/GEO/ED.CIV Miss xxx 15,0 , …

Member Avatar for vlady
0
120
Member Avatar for FALL3N

Perhaps use this snippet [url]http://www.daniweb.com/software-development/python/code/257449[/url] instead of os.system()

Member Avatar for FALL3N
0
293
Member Avatar for maddocspace

I didn't run your code, but it seems to me that lines 45-47 remove the lines that start with "-". I suppose there was some reason why you wrote this block of code ?

Member Avatar for maddocspace
0
297
Member Avatar for rzufelt

As you can see, smtplib uses another module called 'email' which is a package in the standard library. I think you should rename your program to something else than 'email.py' (also why is your script in a folder called 'dont_use' ? Perhaps you should not use it :).

Member Avatar for Gribouillis
0
213
Member Avatar for vlady

The problem is that you're passing a string 'fyzika' to add_mark() instead of a Cpredmet object. I think it would be easier if self.predmety was a dictionary [icode]name --> Cpredmet instance with that name[/icode]. For example you would write [code=python] def add_subject(self, predmet): ''' @param predmet: objekt typu predmet ''' …

Member Avatar for vlady
0
92
Member Avatar for pwolf

It's not a real life program, it's an academic exercise. Basic recursion is related to the mathematical notion of 'induction formula'. Here the more obvious induction formula is that [icode]x ** y = x * (x ** (y-1))[/icode]. From this idea, you should be able to write a recursive function. …

Member Avatar for TrustyTony
0
214
Member Avatar for joryrferrell
Member Avatar for ron126
Member Avatar for MBPFAN

You must learn to read the traceback, which is [code=text] File "./jeuidiot.py", line 18 print "Could there be a key? ^ SyntaxError: EOL while scanning string literal [/code] It means that python encountered an End Of Line error at line 18 while the parser was scanning a literal string. I …

Member Avatar for MBPFAN
0
1K
Member Avatar for manisha

I suppose that you are using numpy for matrix computations, aren't you ? What's the content of the matrices, real numbers ? I think it would be helpful if you post a short working example of a too long computation which you would like to speed up.

Member Avatar for manisha
0
235
Member Avatar for floatingshed

Normally, such redirection is done with a return statement or by raising an exception. I suppose that checkdir() is called by some other function which needs an opened directory, one way to do it is to return a boolean from checkdir [code=python] def other_function(self): ... if not self.checkdir(): return # …

Member Avatar for Gribouillis
0
272
Member Avatar for hamidvosugh

There is also [icode]re.search(r'\b3\b', '13 12 333 453 2 3 433')[/icode] but it will match -3 too.

Member Avatar for Gribouillis
0
160
Member Avatar for Thisisnotanid

You could first install the numpy and scipy modules which contain many special functions. To answer tour second question, you want to write a separate module containing your own special functions. For example write a mymathfuncs.py file containing [code=python] # mymathfuncs.py import numpy def arccoth(z): """Arc hyperbolic cotangent""" return numpy.arctanh(1.0/z) …

Member Avatar for Thisisnotanid
0
384
Member Avatar for floatingshed

It would help if we could see the file names. Can you run the following session with your python interpreter and post the output (with [b][code][/b] tags): [code=python] >>> import os >>> p = u"C:/path/to/folder/containing/input/files" # <-- don't forget the leading u >>> L = os.listdir(p) >>> print(L) >>> print([s.encode('utf8') …

Member Avatar for NewbieXcellence
0
2K
Member Avatar for Vkitor

Why do you want your program to sleep ? You program does nothing but wait between clicks, isn't that sufficient ? If you add a sleep() somewhere, the gui will be unresponsive while the program sleeps.

Member Avatar for TrustyTony
0
173
Member Avatar for bkribbs

The simplest way is [code=python] import subprocess subprocess.call("./a /System/library/extensions/applehda.kext", shell=True) [/code] If you want exit status, output and error from your command, you can also try [url]http://www.daniweb.com/software-development/python/code/257449[/url]

Member Avatar for ihatehippies
0
139
Member Avatar for mr_noname
Member Avatar for snippsat
0
269
Member Avatar for TF401

Why don't you want to use existing programs ? It simply means rewriting these programs in your own code.

Member Avatar for ihatehippies
0
357
Member Avatar for Lucaci Andrew

I would say that the time complexity of the first function is O((j-i) Log(j-i)). The rough argument is this: it is obvious that the number of 'print' only depends on j-i. Call f(z) the number of items printed when prel(x, i, j) is called with an interval length z = …

Member Avatar for Lucaci Andrew
0
229
Member Avatar for Gribouillis

I discovered and installed a firefox addon called Remote Control. This addon starts a telnet server which lets you send javascript commands to the firefox web browser. Combined with python telnetlib module, it becomes very easy to reload or change the content of a tab in a running firefox from …

Member Avatar for Gribouillis
0
928
Member Avatar for M.S.

There are python modules to parse vcards. I pip-installed a module called [b]vobject[/b] and it works: [code=python] #!/usr/bin/env python # -*-coding: utf8-*- import vobject cards = ["""BEGIN:VCARD VERSION:2.1 REV:20110913T095232Z UID:aac119d5fe3bc9dc-00e17913379d6cc8-3 N;X-EPOCCNTMODELLABEL1=First name:;Maj;;; TEL;VOICE:09120000000 X-CLASS:private END:VCARD""", """BEGIN:VCARD VERSION:2.1 REV:20110228T083215Z UID:aac119d5fe3bc9dc-00e17b0693898c98-4 N;X-EPOCCNTMODELLABEL1=First name:;Ali jahan;;; TEL;VOICE:09120000001 X-CLASS:private END:VCARD""", """BEGIN:VCARD VERSION:2.1 REV:20110228T083510Z UID:aac119d5fe3bc9dc-00e17b069df653a0-5 N;X-EPOCCNTMODELLABEL0=Last …

Member Avatar for snippsat
0
2K
Member Avatar for apeiron27

Here is a possible solution without regexes [code=python] def add_dash(str1, str2): src = iter(str2) return "".join('-' if x == '-' else next(src) for x in str1) s1 = "75465-54224-4" s2 = "245366556346" print add_dash(s1, s2) """my output --> 24536-65563-4 """ [/code] Notice that the 6 at the end of s2 …

Member Avatar for Gribouillis
0
107
Member Avatar for Ismatus3

If you're with python 2, try ssh with paramiko. See this thread for examples [url]http://www.daniweb.com/software-development/python/threads/405462[/url]

Member Avatar for Ismatus3
0
2K
Member Avatar for Tcll

I suppose that you normally access your own website using an ftp client, so you should be able to list remote directories with the ftplib module.

Member Avatar for Tcll
0
168
Member Avatar for Gribouillis

These two functions compute the orders of the lowest bit and the highest bit set in the binary representation of an integer. I expect them to handle securely very large integer values.

Member Avatar for Gribouillis
1
2K
Member Avatar for soltak

Did you try [code=python] next(os.walk(directory)) [/code] In the doc, it seems that os.walk only works with strings (unicode), so that you shouldn't have encoding/decoding issues.

Member Avatar for soltak
0
2K
Member Avatar for iPanda

The program has no way to know it was launched with a subprocess.call() statement. What you could do is try to launch the program with a command line in a terminal (or cmd window) to see if it works. A command that works in shell should also work in subprocess.call() …

Member Avatar for iPanda
0
243
Member Avatar for apeiron27

No it doesn't work: [code=python] >>> a = pack('<I', 3) >>> b = pack('<I', 257) >>> a '\x03\x00\x00\x00' >>> b '\x01\x01\x00\x00' >>> a < b False [/code] pack() returns strings, which are compared in lexicographical order. == tests should work.

Member Avatar for TrustyTony
0
125
Member Avatar for pwolf

[QUOTE=pwolf;1737303]whilst this thread is open, could you help me with another problem? this time i am to determine whether its scalene or not, so i wrote; [CODE] def isScalene(x, y, z): if x <= 0 or y <=0 or z <=0: return False elif x == y or x == …

Member Avatar for TrustyTony
0
3K
Member Avatar for John_Cro

I guess it could be something like this in C [code=C] #include <math.h> double dot(int sz, double *u, double* v){ int i; double res = 0.0; for(i = 0; i < sz; ++i) res += u[i] * v[i]; return res; } void cumul(int sz, double *u, double* res){ int i; …

Member Avatar for Gribouillis
0
259
Member Avatar for Gribouillis

This snippet defines a decorator @mixedmethod similar to @classmethod, which allows the method to access the calling instance when it exists. The decorated functions have two implicit arguments [i]self, cls[/i], the former having a None value when there is no instance in the call. Using python's descriptor protocol, the implementation …

Member Avatar for TrustyTony
1
435
Member Avatar for debasishgang7
Member Avatar for snippsat
0
285
Member Avatar for moroccanplaya

There are problems sometimes with the interpretation of end of line characters, depending on your platform and the program which opens your file. If your output file was written using opening mode 'wb', try mode 'w', it may solve the issue.

Member Avatar for moroccanplaya
0
87
Member Avatar for iraj.jelo

I don't know anything of PyQt, but usually GUI toolkits have special ways of handling threads. Also even in non gui programs, python threads are usually started with the threading module instead of the lower level thread module. Reading this tutorial [url]http://diotavelli.net/PyQtWiki/Threading,_Signals_and_Slots[/url], it seems that subclassing QThread would be a …

Member Avatar for Gribouillis
0
3K

The End.