3,386 Posted Topics

Member Avatar for Tommymac501

There is one file crlf.py in scripts directory, is it relevant? [CODE]D:\Python27>cat Tools\Scripts\crlf.py #! /usr/bin/env python "Replace CRLF with LF in argument files. Print names of changed files." import sys, os def main(): for filename in sys.argv[1:]: if os.path.isdir(filename): print filename, "Directory!" continue data = open(filename, "rb").read() if '\0' in …

Member Avatar for TrustyTony
0
11K
Member Avatar for lewashby

In principle it is like any other parameter. It goes to objects creation method __init__which makes that object parent or 'holder' of the new widget. So it has nothing to do with inheriting but way off defining the hierarchy of widgets.

Member Avatar for TrustyTony
0
278
Member Avatar for WildBamaBoy

Something to this direction, if I understood your intention? [CODE]import os class Folder: def __init__(self, path): if os.path.isdir(path): self.path=os.path.realpath(path) else: raise WindowsError, 'Invalid path name: '+path def __str__(self): os.system("cls") res = "Folders in %s\n" % self.path return res+'\n\t'.join( filter(os.path.isdir, [os.path.join(self.path,p) for p in os.listdir(self.path)])) def cd(self,directory): curdir = os.path.join(self.path, directory) …

Member Avatar for WildBamaBoy
0
113
Member Avatar for monjuri

Temp file and passing the name is maybe easy solution. Feels maybe clumsy, but should work. Other thing maybe would to define new function in your C++ code using Python interface specification. Then there is the solution of using Shedskin for a small python program which uses dict as parameter …

Member Avatar for monjuri
0
263
Member Avatar for parijat24

Can you give exact math formula and/or example with few values and right result for that limited example.

Member Avatar for Beat_Slayer
0
92
Member Avatar for cwarn23

Now the new post icons don't update. I do not know exact anatomy of problem of this thread, but do not want to start new thread for maybe well known situation. You can reply to this and people can check the reason of problem. The proof of solution is of …

Member Avatar for TrustyTony
0
117
Member Avatar for Kanem

I think you are after more like this, just change in your own units and take out jump from midnight to next morning 5 o'clock if you want. Two speeds of advancing the time you can best deal by multiple increases of time per clock tick, in this code the …

Member Avatar for TrustyTony
0
146
Member Avatar for Member 784833
Member Avatar for prashanth s j

Looks the number is at end of string so you could do: [code]>>> output='bnu kn uhx dwtjp 1' >>> output.rsplit(' ',1) ['bnu kn uhx dwtjp', '1'] >>> int(output.rsplit(' ',1)[-1]) 1[/code]

Member Avatar for Beat_Slayer
0
104
Member Avatar for modalgvr

[QUOTE=vegaseat;1267578]Here is one solution ... [code]list1 = [ "['1426', '1095', '1094', '1093', '1092', '974', '869', '1572']\n", "['1495', '1305', '1264', '1227', '1215', '1142', '1141', '1115']\n", "['1001', '997', '927', '904', '871', '776', '712', '612']\n", "['567', '538', '429', '415', '332', '326', '250', '247']\n", "['246', '245', '244', '155', '145', '133', '101']\n"] list2 = [] …

Member Avatar for TrustyTony
0
178
Member Avatar for leiger
Member Avatar for blah32

If you are only concerned with functioning in Windows, there is ready possibility, even not built in directly: [URL="http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html#shell"]Win32 shell: use SHFileOperation[/URL]: [QUOTE]Finally, the Platinum Option is probably to use the shell functionality which will offer the same facilities as Explorer, including animated icons, the recycle bin and renaming on …

Member Avatar for blah32
0
135
Member Avatar for Dan08
Member Avatar for TrustyTony

From python.org official website: [URL="http://python.org/download/releases/2.7/"]Python 2.7[/URL] [B][I]Python 2.7 was released on July 3rd, 2010[/I].[/B] Python 2.7 is scheduled to be the last major version in the 2.x series before it moves into an extended maintenance period. This release contains many of the features that were first released in Python 3.1. …

Member Avatar for TrustyTony
2
442
Member Avatar for turnerca902

Quite simple with the code snippet I posted today, only add removing of quoting. [CODE]# text based data input with data accessible # with named fields or indexing from __future__ import print_function ## Python 3 style printing from collections import namedtuple import string filein = open("cb2.txt") quotes = ''\"' datadict …

Member Avatar for turnerca902
0
455
Member Avatar for lewashby
Member Avatar for Skyelher

Sometimes I have used: [CODE] always=True while always: # code [/CODE] Sometimes when there is meaningful starting value for finishing condition you can use: [CODE] value=' ' while value: value = raw_input('Give value or empty line to finish: ') # process value [/CODE] Repeating until break is OK, but the …

Member Avatar for griswolf
0
150
Member Avatar for TrustyTony

My Python has started to imagine that square root of -1 is 1, so be careful with ** and unary -. [CODE]print (-1**0.5) ## ** binds stronger than unary minus! i=-1 print "Square root of %i is %f" (i,i**0.5) # gives proper error """ Output: -1.0 Traceback (most recent call …

Member Avatar for Skyelher
0
341
Member Avatar for TrustyTony

See the link ([URL="http://norvig.com/sudoku.html"]Solve Every Sudoku Puzzle[/URL] for fine description of logic of the code) I attach the top95.txt file of tough problems and the sudoku claimed toughest of all time by Finnish mathematician Arto Inkala ([URL="http://www.kristanix.com/sudokuepic/worlds-hardest-sudoku.php"]The Worlds Hardest Sudoku Puzzle[/URL]) Solving this was piece of cake for the code, …

Member Avatar for TrustyTony
0
1K
Member Avatar for parijat24

This is Python forum and it is easy to do in Python, but in Linux or other unix style system you can use backquotes. So to copy listed files from file 'file' to directory 'directory' you could do: [CODE=bash]cp `cat file` directory[/CODE]

Member Avatar for TrustyTony
0
98
Member Avatar for hondros

Use [B][code=c][/B] for C part [code=C] #include <windows.h> #include <iostream> using namespace std; int main() { HANDLE hOut; char Letters[5]; COORD Where; DWORD NumRead; int i; hOut = GetStdHandle(STD_OUTPUT_HANDLE); cout << "A line of little consequence." << endl; Where.X = 4; ReadConsoleOutputCharacter(hOut, Letters, 5, Where, &NumRead); cout << "5 letters …

Member Avatar for hondros
0
350
Member Avatar for gonzigg

I would recommend changing organisation of your code. But if you want keep your style, you must only set the x to zero after error message. No recursive call.

Member Avatar for faby
0
180
Member Avatar for shashimgowda8

Check earlier threads, like [url]http://www.daniweb.com/forums/post793476.html#post793476[/url]

Member Avatar for shashimgowda8
-1
238
Member Avatar for jazz_vill

Is it doctorate level or major level work? [QUOTE]thesis [ˈθiːsɪs] n pl -ses [-siːz] 1. (Social Science / Education) a dissertation resulting from original research, esp when submitted by a candidate for a degree or diploma 2. a doctrine maintained or promoted in argument 3. (Social Science / Education) a …

Member Avatar for TrustyTony
0
140
Member Avatar for Tubbychief

You do not need to count time yourself if you do not need to show the time continuously on screen. If the starting to race is together: [LIST=1] [*]Record race starting time [*]When racer's time is needed show difference of current time and starting time. [/LIST] To get general timer …

Member Avatar for TrustyTony
0
112
Member Avatar for YasaminKh

Put all formats to %s and see the values, one of %g parameters is not float needed for scientific format number. Or do [CODE]print [type(i) for i in (indexvalue_list[i], mean_list[i], kapa_list[i], LDmean_list[i], kapaerror_list[i])][/CODE] To see which type the values are. You can also use **0.5 instead of sqrt().

Member Avatar for YasaminKh
0
196
Member Avatar for kosco

Some examples of the solutions, first filtering in lines starting "Node", then filtering out lines starting '1 ' In first solution I print out the list, in second I leave them in list from were they can be printed or used for other purposes. [CODE] test=""" 1 8724593564 2 153 …

Member Avatar for vukman
0
286
Member Avatar for shannonkr

Here is one way, as input mus be strings in multiple lines we go little roundabout: [CODE]import sys,cStringIO inputs=[str(i) for i in range(20)] sys.stdin=cStringIO.StringIO('\n'.join(inputs)) for i in range(20): print int(raw_input('Enter number: '))*i "" Output: Enter number: 0 Enter number: 1 Enter number: 4 Enter number: 9 Enter number: 16 Enter …

Member Avatar for TrustyTony
0
76
Member Avatar for ihatehippies

I often find myself writing small list comrehensions in sequence and after puting the normal for by putting them in opposite order in the end of list comprehension. It is maybe possible to use generator expressions to imitate for loop break cleaner than zero division error. Maybe better to use …

Member Avatar for snippsat
0
11K
Member Avatar for echellwig

Do before replace [CODE]print popdata[0][5], type(popdata[0][5])[/CODE] To check your assumptions about it being list of floats. You should have got this error: [CODE]Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> [0.02,10.05,34,56,0.02,0.199999].replace(0.02,0) AttributeError: 'list' object has no attribute 'replace' [/CODE] How to replace float near some value: [CODE]>>> …

Member Avatar for echellwig
0
576
Member Avatar for YasaminKh

Would this change to lines 30.-34. help? [CODE]#Iterate over all SCALAR_AVERAGEs and put their values into the lists #above. for sa in sa_list: iv1, _, iv2 = sa.attributes.getNamedItem('indexvalue').nodeValue.partition('--') iv1,iv2 = eval(iv1), eval(iv2) print '%s != %s indexvalues not same. Not interesting' % (iv1,iv2) if iv1 != iv2 else 'indexvalues same …

Member Avatar for TrustyTony
0
332
Member Avatar for YasaminKh

That would be probably then most pythonically: [CODE] new_error_list = [err*err for err in error][/CODE] [iCODE]err**2[/iCODE] is same as [iCODE]err*err [/iCODE]of course if you prefer. And in Python it is common to reuse the list and not to save result with new name (error instead of new_error_list), but sometimes it …

Member Avatar for YasaminKh
0
187
Member Avatar for aframe

This does the thing, I do not know how good programming style it is to change own code, though: [CODE]## My program import sys def between(left,right,s): before,_,a = s.partition(left) a,_,after = a.partition(right) return before,a,after my_value=2160278.18574 print 'Old value',my_value my_value=1.2*my_value print 'New value', my_value my_code=open(sys.argv[0]).read() beginning,value,rest=between('my_value=','\n',my_code) open(sys.argv[0],'w').write(beginning + 'my_value=' + str(my_value) …

Member Avatar for griswolf
0
2K
Member Avatar for patto78

Try replacing ~ with $HOME Also prove [CODE]python -m file.py[/CODE] You could also do an alias for python or script file in your home directory or ¨/bin directory. With proper setup your Linux (??) can recognize .py files automatically and should run them without needing the python in front. [url]http://www.daniweb.com/code/snippet241988.html[/url]

Member Avatar for patto78
0
212
Member Avatar for heyday21c

This is loop to generate the phrases as lists. Add counting and put list back to string by your self, and add storage of phrases,input/output according to your requirements. [CODE]sentence="I love you very much" words=sentence.split() words_in_sentence=len(words) phrases=[] for phraselength in range(2,words_in_sentence): for startword in range(words_in_sentence-phraselength): print words[startword:startword+phraselength] [/CODE]

Member Avatar for vegaseat
0
1K
Member Avatar for TrustyTony

The code from my answer to thread: [url]http://www.daniweb.com/forums/thread292949.html[/url] Any field names with any same separator separating the values. This is straight text file reading routine, see the original thread for csv module based code. sample.dat: [CODE]id; name; email; homeaddress 123; gishi; gishi@mymail.com; 456 happy st. 345; tony; tony.veijalainen@somewhere.com; Espoo Finland …

Member Avatar for TrustyTony
0
1K
Member Avatar for ChargrO

That is not your code. That is code I wrote for a base of checkers program in earlier thread, including comments and diag_stripe routine for producing the board. Remember to mention the origin of your code or at least not claim that you wrote it.

Member Avatar for TrustyTony
0
142
Member Avatar for daviddan2010

Luhn test is one Rosetta code task: [url]http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers[/url] Python solution on that page currently: [CODE] def luhn(n): r = [int(ch) for ch in str(n)][::-1] return (sum(r[0::2]) + sum(sum(divmod(d*2,10)) for d in r[1::2])) % 10 == 0 for n in (49927398716, 49927398717, 1234567812345678, 1234567812345670): print(n, luhn(n)) """Output: (49927398716L, True) (49927398717L, False) …

Member Avatar for daviddan2010
0
2K
Member Avatar for mastermoo420

[QUOTE=mastermoo420;1263113][url]http://paste.pocoo.org/show/231731/[/url] My problem is listed here... There shouldn't really be a reason (as far as I can see) with memory... If there's another way to get a dictionary from a .txt file that'd work/is more efficient, I'm looking for help. P:[/QUOTE] This line is stupid: [CODE]dictionary_being_manipulated = eval(dictionary_opened.read())[/CODE] You are …

Member Avatar for TrustyTony
0
62
Member Avatar for foren

Could you give input and desired output of your program. Use manage attachments and post the input file zipped. If you want to count something from file see this: [url]http://www.daniweb.com/forums/post658840.html#post658840[/url]

Member Avatar for foren
0
241
Member Avatar for cbtetech

Change those variables to dict current variable names. Other way is to change the raw_input to input in your change code, but that is unsafe as it allows arbitrary expressions. The values should also be coordinate tuples, not strings.

Member Avatar for TrustyTony
0
328
Member Avatar for cableguy31

[QUOTE=snippsat;1261659]Here is an alternative with "endswith" thats works fine for this. [/QUOTE] Just one small thing is that it is quite rare for the filename to end with with both .txt and .jpg, so I would fix logic little: [CODE]aFile = 'test.jpg' for ext in ['.txt', '.jpg', '.zip']: if aFile.lower().endswith(ext): …

Member Avatar for TrustyTony
0
151
Member Avatar for Priyesh_17

Did you check my link to Java programmers? It warned that in many cases it is best to keep hands out of XML in Python, if it is not for interoperativity. You can use my between code snippet if you do not want to check the validity of the files …

Member Avatar for TrustyTony
0
130
Member Avatar for cadtel

At least you should store label before doing .grid: [CODE] self.input_1_lbl=Label(self, text="Side A" ).grid(row=3, column=0, columnspan=1) print('Created', self.input_1_lbl) [/CODE] Output [CODE]Created None [/CODE]

Member Avatar for TrustyTony
0
194
Member Avatar for Pykoda

What do you mean by update? Copying newer version over old version? Not touching files with same name as exist in destination, but copying files with new name? How about files deleted from source? Have you by the way looked my code snippet on watching change in list of directories?

Member Avatar for TrustyTony
0
125
Member Avatar for cableguy31

check the os.listdir().endswith('.txt') or similar in Windows disks or do file command in Linux script and capture the result, use for example: [url]http://www.daniweb.com/code/snippet257449.html[/url]

Member Avatar for cableguy31
1
747
Member Avatar for TrustyTony

This is must read if you learned Java before Python: Python Is Not Java: [url]http://dirtsimple.org/2004/12/python-is-not-java.html[/url]

Member Avatar for snippsat
1
654
Member Avatar for Jeramy

For the day modulo 15 you can use: [CODE]## get 0..15 int from current day from datetime import date print(date.today().day % 16) [/CODE] So something like this (if you have pre-existing bck directory in place before hand): [CODE]from datetime import date import os import shutil ## get 0..15 int from …

Member Avatar for Jeramy
0
110
Member Avatar for echellwig

[CODE] numbers="12560 36520 1763" numberlist= numbers.split() print("First number is %i." % numberlist[0])[/CODE]

Member Avatar for echellwig
0
180
Member Avatar for capson

Variable PNi is uninitialized and variables PN0, PN1 and PN2 are unused. Comparison of NULL fails and it is not in statement. [CODE]PN0=[0,0,1,1,0,1,0,1] PN1=[1,1,0,0,0,0,1,0] PN2=[0,0,0,0,1,0,0,0] PN=[0,0,0,0,0,0,0,0] NULL==[0,0,0,0,0,0,0,0] for i in range(3): if PNi.count(1) < 2: PN=[sum(pair) for pair in zip(PN, PNi)] print('Yes') else: PNi=NULL print('No') """Output: Traceback (most recent call …

Member Avatar for capson
0
118

The End.