2,646 Posted Topics

Member Avatar for HTMLperson5

`os.system()` is a (deprecated) function to run another program from your python program. Changing your process' working directory is different from starting another program. Use `os.chdir(path)` to change the current working directory and `os.getcwd()` to get the current working directory.

Member Avatar for Gribouillis
0
192
Member Avatar for 4evrmrepylrning

A known solution is import codecs file = codecs.open(path, encoding='iso8859-1') see if it works for you.

Member Avatar for Gribouillis
0
210
Member Avatar for Stefano Mtangoo

I have these links [url]http://www.iconlet.com/browse[/url] [url]http://www.daniweb.com/forums/thread12398.html[/url]

Member Avatar for jsdevel
0
165
Member Avatar for HTMLperson5

Did you read the sticky thread [projects-for-the-beginner](http://www.daniweb.com/software-development/python/threads/32007/projects-for-the-beginner) which contains many ideas in this direction ?

Member Avatar for HTMLperson5
0
218
Member Avatar for kuchi

Use recursion: write a function F(dictionary) to write a dictionary. In the function's body, iterate over the dictionary items, and if one of the item contains a new dictionary, call F(subdictionary) again to write this dict.

Member Avatar for TrustyTony
0
245
Member Avatar for HTMLperson5

I once wrote a small class to help beginners write text based games, [see here](http://www.daniweb.com/software-development/python/code/217215/a-class-for-menu-based-terminal-applications). See if it can help you (you can replace Print with print in the code and remove the cbprint import).

Member Avatar for Gribouillis
0
4K
Member Avatar for srk619

Try this [code=python] # python >= 2.5 def isLeapYear(year): return False if year % 4 else True if year % 100 else not year % 400 [/code] :)

Member Avatar for HiHe
0
657
Member Avatar for 4evrmrepylrning

All this would be more serious if you could describe the exact syntax *rules* of the input string.

Member Avatar for 4evrmrepylrning
0
218
Member Avatar for drichird

Yes, your statements are correct. Here is how you could implement the cpp static field behavior in python using an accessor function instead of an attribute from __future__ import print_function from functools import partial # preliminary definitions _default = object() def _helper_static_cpp(container, value = _default): if value is _default: return …

Member Avatar for Gribouillis
0
807
Member Avatar for thanadaray

> I have many single float but how I can make then to be list of float? It's fairly easy. At the top of your program, you add `thelist = list()`. Then when you want to add a score to the list, you write `thelist.append(score)`. Finally, add `print(thelist)` at the …

Member Avatar for HiHe
0
201
Member Avatar for thanadaray
Member Avatar for Gribouillis

This code snippet provides methods to convert between various ieee754 floating point numbers format. For example double precision to single precision. The format is given by a pair (w, p) giving the size in bits of the exponent part and the significand part in the ieee754 representation of a number …

Member Avatar for TrustyTony
1
5K
Member Avatar for swissknife007

The best algorithm is gaussian elimination. Read this first [Click Here](http://en.wikipedia.org/wiki/Gaussian_elimination)

Member Avatar for Gribouillis
0
154
Member Avatar for el33t

I suggest to write it as while((tr < row) && (grid[tr][tc]=='0'||grid[tr][tc]==s[i]) && (count<strlen(s))) { ++count; ++tr; } If `tr < row` fails, `grid[tr]` will not be computed :)

Member Avatar for Gribouillis
0
183
Member Avatar for debasishgang7

Here is a way using my snippet on [non recursive tree traversal 1.4](http://www.daniweb.com/software-development/python/code/395270/generic-non-recursive-tree-traversal) from functools import partial import walktree as wt def subn(letters, k, node): if len(node) == k: return for x in letters: yield node + x for path in wt.walk("", partial(subn, "ABC", 3), wt.event(wt.leaf)): print path[-1] """my output …

Member Avatar for TrustyTony
0
1K
Member Avatar for pawel1

Here is a working version with a varying 'guessrange' :) # CPU Guess My Number # # You pick a random number between 1 and 100 # The computer tries to guess it in the fewest attempts # automatically saying if the number is too high or low # or …

Member Avatar for TrustyTony
0
262
Member Avatar for weblover

Here is one way to do it from operator import itemgetter import itertools as itt valuearray = [['A', '21', '45'], ['A', '12', '23'], ['A', '54', '21'], ['A', '15', '54'], ['B', '23', '53'], ['B', '34', '53'], ['B', '32', '54'], ['B', '24', '13'], ['C', '31', '43'], ['C', '42', '54'], ['C', '35', '54'], …

Member Avatar for Gribouillis
0
441
Member Avatar for TrustyTony
Member Avatar for TrustyTony

This is a typical use case for the `__new__()` method: class BalancedTernary(long): def __new__(cls, n): instance = long.__new__(cls, balanced_ternary_value(n) if isinstance(n, str) else n) return instance def __repr__(self): return make_balanced(self) __str__ = __repr__ Your code seems to work now.

Member Avatar for Gribouillis
0
277
Member Avatar for drichird

There is no such rule. `import myScript` reads the file on the disk if there is no module in `sys.modules['myScript']`. This module may exist even if the name myScript is not defined in the current global namespace. Apparently, your app closes and reopens the shell window in the same python …

Member Avatar for drichird
0
391
Member Avatar for Suffii

It seems that the signature of Insert is `Insert(self, item, pos, client_data=None)`, [See here](http://www.wxpython.org/docs/api/wx.ListBox-class.html#Insert) .

Member Avatar for Gribouillis
0
233
Member Avatar for heinlein_

You can use sub() with a method as argument import re from functools import partial repl_dict = {'cat': 'Garfield', 'dog': 'Oddie' } def helper(dic, match): word = match.group(0) return dic.get(word, word) word_re = re.compile(r'\b[a-zA-Z]+\b') text = "dog ate the catfood and went to cat's bed to see dog dreams on …

Member Avatar for heinlein_
0
8K
Member Avatar for Python4Psudo

You are making an uncontroled use of recursion: `Get_num()` calls `Get_num()`, etc. Each function must have a precise task to do, which can be described in a short documentation string. Look at the following pseudo code for example # THIS IS PSEUDO CODE, NOT REAL CODE def main_job(): """Repeatedly ask …

Member Avatar for Python4Psudo
0
193
Member Avatar for jbennet

Is there a way to see the threads by last post first in the new system ?

Member Avatar for Airshow
0
2K
Member Avatar for vmars

Normally in windows, if you click on a .py file, it runs the file in a cmd console. If you want to run the program without console, you can rename it with the .pyw extension.

Member Avatar for vmars
0
2K
Member Avatar for Niner710

You will probably find a way to plot the data in the [matplotlib gallery](http://matplotlib.sourceforge.net/gallery.html) . Each picture comes with its source code.

Member Avatar for Niner710
0
243
Member Avatar for adrigreat14

Here is how you can find which variables are None [code=python] missing_list = [ i for (i, z) in enumerate((v, u, a, t)) if z is None ] [/code] This returns a sublist of [0, 1, 2, 3] with the indexes of the variables equal to None.

Member Avatar for adrigreat14
0
281
Member Avatar for 4evrmrepylrning

As your data file looks like xml, I obtained some results very easily using module xml.parsers.expat. Here is the code. It uses this code snippet [i]adaptstrings[/i] [url]http://www.daniweb.com/software-development/python/code/389929[/url] (this could be optimized later). [code=python] from itertools import chain from adaptstrings import adapt_as_file import xml.parsers.expat PREFIX = "<document>\n" SUFFIX = "</document>\n" def …

Member Avatar for Gribouillis
0
277
Member Avatar for zephiechan

When you call [icode]character.useItem(item)[/icode] you want the item to update the character's statistics using an item-specific dynamic rule. One way to do this is to define an action function for the item instead of a dictionary of statistics [code=python] class Character(object): def __init__(self, name): self.name = name def useItem(self, item): …

Member Avatar for Gribouillis
0
141
Member Avatar for A_Dubbs

If you've learned about lists, a good way to store the numbers would be to append them to a list. But as gerard4143 said, you don't really need to store them.

Member Avatar for B dawg
0
941
Member Avatar for minimee120

Your third parameter breaches the contract. It said that the third parameter must be the number of steps to be taken. It means that randint() must be called exactly this number of times.

Member Avatar for M.S.
0
158
Member Avatar for arunpawar

Many python functions which used to return lists now return iterables. You can convert it to a list with the list() constructor [code=python] list(map(lambda x,y:x+y, a,b)) [/code] This produces the same as [code=python] [x + y for x, y in zip(a, b)] [/code] The use of map() is deprecated in …

Member Avatar for Gribouillis
0
96
Member Avatar for Sunciti
Member Avatar for petrovitch
Member Avatar for 4evrmrepylrning

An improvement would be to use the argparse module to handle the command line. It would be especially useful to learn if you need to write a lot of scripts.

Member Avatar for Gribouillis
0
148
Member Avatar for Niner710

You could matrix multiply on the right by matrix with 3 rows and 1 column [16*16, 16, 1].

Member Avatar for TrustyTony
0
135
Member Avatar for LRNPHP

It's not exactly a python question, although your problem could probably be programmed in python. Apparently you are trying to extract something from File.txt using the 2 columns ValueA and ValueB. Can you explain with more details the contents of File.txt and the expected output ?

Member Avatar for Gribouillis
0
95
Member Avatar for welshly_2010
Member Avatar for Gribouillis
0
91
Member Avatar for nosehat

I found this [url]http://stackoverflow.com/questions/4799553/how-to-update-one-file-in-a-zip-archive[/url] . It's not python, but it could be a starting point. In windows you could try with 7zip.

Member Avatar for nosehat
0
1K
Member Avatar for inuasha
Member Avatar for Gribouillis
0
218
Member Avatar for ozzyx123

You should be able to install xlwt with the pip installer. For this type [code=text] sudo pip install xlwt [/code] in a terminal (with a working internet connection). If you don't have pip, then you must install pip first. For this type [code=text] sudo easy_install pip [/code] If you don't …

Member Avatar for peter_budo
0
658
Member Avatar for hughesadam_87

[QUOTE=shoemoodoshaloo;1777559]So basically "is" could be repaced with if id(a) == id(b)?[/QUOTE] Exactly, because id(a) is nothing but the C pointer to object a converted to integer (see the function builtin_id in [url]http://svn.python.org/view/python/trunk/Python/bltinmodule.c?revision=81029&view=markup[/url]) , and the [b]is[/b] operator is implemented by comparing the pointer values (in [url]http://svn.python.org/view/python/trunk/Python/ceval.c?view=markup[/url]) [code=c] static PyObject * …

Member Avatar for Gribouillis
0
166
Member Avatar for AJkiter
Member Avatar for floatingshed

Another solution is to catch the apps output in your python program. You may need to change the way your apps are launched.

Member Avatar for floatingshed
0
202
Member Avatar for fafa70

At first sight, I would say that it is not possible. If you look in the source code of the turtle module (in python 2.7), you'll see that the Turtle instances all use a [i]singleton[/i] object called turtle._screen. It means that multiple windows are probably not implemented.

Member Avatar for fafa70
0
4K
Member Avatar for puddlejumper406

Here is a good starting point [url]http://www.daniweb.com/forums/announcement.php?f=8&announcementid=2[/url] .

Member Avatar for puddlejumper406
0
119
Member Avatar for karan_kanna

It is possible that the (key, value) pairs where pickled one by one to the file using multiple calls to dump(). In this case, you can read them with multiple calls to load(). See this example [code=python] """ Example showing multiple calls of pickle.dump() to the same file. The objects …

Member Avatar for Gribouillis
0
210
Member Avatar for hughesadam_87

Hm, try this [code=python] outstr = "\n".join("\t".join(str(i*j) for j in range(1, 13)) for i in range(1, 13)) print outstr [/code]

Member Avatar for hughesadam_87
0
121
Member Avatar for floatingshed

Also the function splitIt() from this post [url]http://www.daniweb.com/software-development/python/code/217111/969269#post969269[/url] works for lists.

Member Avatar for hughesadam_87
0
157
Member Avatar for hughesadam_87

I think there are a lot of misconceptions about classes in your approach. First, a more accurate name for class Person would be MinimalDataThatThisProgramNeedsToStoreAboutAPerson. It means that the purpose of a class Person is not to mimic a person from the real world but to provide some space in memory …

Member Avatar for hughesadam_87
0
146

The End.