2,646 Posted Topics

Member Avatar for n.utiu

There must be something else in your program. In principle, these 2 lines don't send anything to the console.

Member Avatar for n.utiu
0
83
Member Avatar for Siyabonga Gama
Member Avatar for kjock002
Member Avatar for Gribouillis
0
116
Member Avatar for biomed

I agree with you that line and text manipulations are too limited to handle the problem. You can easily write python functions to transform your lines into python tuples which are much easier to handle, compare, sort, etc. For example here is a function to read the file as a …

Member Avatar for Gribouillis
0
97
Member Avatar for froggy1

Use the interpreter ! [code=python] >>> help(str.replace) Help on method_descriptor: replace(...) S.replace (old, new[, count]) -> string Return a copy of string S with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced. [/code]

Member Avatar for froggy1
0
149
Member Avatar for fur8ar

It's strange, it works on my machine with python 3.1. A possibility is that you have a file calendar.py in your directory or in the python path which hides the standard module calendar. If this is so, you should rename this file. To see if this is the case, try …

Member Avatar for fur8ar
0
101
Member Avatar for G_S

Why are you trying to install python3 from source ? I'm running Mandriva 2010 on a 64 bits processor and I installed the packages python3 and tkinter3 with the software manager. This gave me a working python 3 with tkinter. [code=python] Python 3.1.1 (r311:74480, Jan 5 2010, 18:03:14) [GCC 4.4.1] …

Member Avatar for G_S
0
243
Member Avatar for pyprog

You can go this way [code=python] >>> l = [[1, 2, 1],[1, 1, 2],[2, 1, 1]] >>> for i, element in enumerate(l): ... l[i] = [x for x in element if x != 1] ... >>> l [[2], [2], [2]] [/code] or even shorter [code=python] >>> l = [[1, 2, …

Member Avatar for vegaseat
0
143
Member Avatar for jozz3

You must open the file [code=python] content = open(fileName).read() [/code]

Member Avatar for Gribouillis
0
141
Member Avatar for ultimatebuster

Perhaps you should write a command line interpreter. See this code snippet [url]http://www.daniweb.com/code/snippet258640.html[/url] .

Member Avatar for Gribouillis
0
82
Member Avatar for aot

[QUOTE=diego.sueiro;1170910]Tech B, Is there a way to this in linux? Regards[/QUOTE] You should experiment with the method warp_pointer in the python-xlib module. (See also XWarpPointer in the xlib documentation). The problem is to find the good arguments to warp_pointer...

Member Avatar for Gribouillis
0
4K
Member Avatar for SgtMe

You can remove the newline at the end of the line with the rstrip method. Also, you can convert a string to int using 'int' [code=python] infile = open("infile.txt", "r") for line in infile: line = line.rstrip("\n") # remove the newline at the end try: line = int(line) # convert …

Member Avatar for snippsat
0
16K
Member Avatar for jozz3

If you want to sort by name, you only need to add [icode]scores = sorted(scores)[/icode] after line 4.

Member Avatar for jozz3
0
2K
Member Avatar for john2oth

Here is another hint: [code=python] word = 'polarity' even_letters = [word[i] for i in range(0, len(word), 2)] odd_letters = [word[i] for i in range(1, len(word), 2)] print(even_letters) print(odd_letters) [/code] Also note that on some linuxes, the dictionary is at /usr/share/dict/words .

Member Avatar for Gribouillis
-4
322
Member Avatar for prashanth s j

If you are speaking of linux' grep command, it does not use the same regexes as python. It uses posix regular expression. You should use grep -E and see [url]http://www.regular-expressions.info/posix.html#bre[/url] or google for more info on the supported regexes. Another solution is to use the [b]grin[/b] program [url]http://pypi.python.org/pypi/grin[/url] which is …

Member Avatar for prashanth s j
0
146
Member Avatar for o0b3600
Member Avatar for Gribouillis
0
275
Member Avatar for Gribouillis

I'm looking for C++ libraries to manipulate real and/or rational polynomials. Does someone know such a library ?

0
136
Member Avatar for jozz3

It's [code=python] "Please enter a number between %s and %s." % (smallestNum, largestNum) [/code]

Member Avatar for jozz3
0
114
Member Avatar for persianprez

line 10 should be [icode]total = sumDivisors(n)[/icode]. Also you can speed this up by adding [icode]total += counter + n/counter[/icode] when [icode]counter < n/counter[/icode] and [icode]total += counter[/icode] when [icode]counter == n/counter[/icode].

Member Avatar for persianprez
0
205
Member Avatar for a.w.howell
Member Avatar for woooee
0
144
Member Avatar for Simes

If you want a better code structure, you could write parts of the structure before the details. For example [code=python] import random def main(): name = get_name() while True: show_menu() answer = get_menu_choice() if answer == "P": play_game(name) elif answer == "V": view_high_scores() elif answer == "Q": break else: print("Please …

Member Avatar for Simes
0
147
Member Avatar for Kruptein

You can read multiple lines with multiple raw_input and have a function which tests if input is complete. Here is an example [code=python] def input_complete(input_list): if ";" in input_list[-1]: return True else: return False def get_input(prompt1, prompt2): L = list() prompt = prompt1 while True: L.append(raw_input(prompt)) if input_complete(L): return "\n".join(L) …

Member Avatar for Kruptein
0
2K
Member Avatar for jeffery12109

I suspect that your function returned None. Try to call it this way [code=python] value = karidInn(day, season, help4, myGame) if value is None: print("GRRRRRRRRRRRRRRRRRR") else: day, season, help4, myGame = value [/code]

Member Avatar for jeffery12109
0
4K
Member Avatar for cp123

According to easygui's doc, you need a file [icode]easygui.py[/icode] in your site-packages directory. Note also that the doc says that using easygui with idle may lead to unpredictable results because idle is already a tkinter application.

Member Avatar for sofiH
0
3K
Member Avatar for soUPERMan

Here is a version that runs. I just removed the last index in the lovers loop [code=python] def displayHappy(): numLimit = input("Enter a positive integer: ") countHappy = 0 countUnhappy = 0 liHappy = [] for num in range(1, numLimit + 1): inNum = num while inNum != 1 and …

Member Avatar for soUPERMan
0
167
Member Avatar for bumsfeld

If you have a 64 bits processor, use a linux system ! Mandriva 2010 gnome is excellent.

Member Avatar for Alq Veers
1
487
Member Avatar for tzushky

You can use the code module, which has classes like InteractiveConsole to evaluate python expressions.

Member Avatar for Gribouillis
0
372
Member Avatar for Andy_Ballard

You need to write interface code between your C++ library and python. A good tool for this is [url=http://www.swig.org/]the swig interface generator[/url] which is well documented. If you know C++, would you be able to write a small program which uses your library and does something useful ? In that …

Member Avatar for Andy_Ballard
0
3K
Member Avatar for Gribouillis

This snippet defines a class LebsegueSet which instances represent sets of real numbers, namely finite unions of intervals. Set theoretical, topological and measure theoretical operations are implemented in pure python. Use freely and enjoy !

1
255
Member Avatar for DifficultUsrnme

1) Yes, everything you manipulate in python is an object, an instance of a class. 2) You never need to declare the type of anything. 3) When a function returns more than 1 value, it returns in fact a *tuple*, one of python's FDT. There is no reason to avoid …

Member Avatar for DifficultUsrnme
0
166
Member Avatar for kedarm

I removed the underscores before 'spamify' and it works [code=c] #include <Python.h> #include <stdio.h> #include <stdlib.h> static PyObject *spam_system(PyObject *self, PyObject *args) { const char *command; int sts; if (!PyArg_ParseTuple(args, "s", &command)) return NULL; sts = system(command); return Py_BuildValue("i", sts); } static PyMethodDef SpamMethods[] = { {"system", spam_system, METH_VARARGS,"Execute a …

Member Avatar for kedarm
0
5K
Member Avatar for cerralife

If you want to impress your teacher, use this [code=python] >>> import re >>> pat = re.compile(r"\w{2}") >>> pat.sub(lambda mo: mo.group(0)[-1::-1], "antidisestablishmentarianism") 'naitidestsbailhsemtnraaiinms' [/code]

Member Avatar for Gribouillis
0
182
Member Avatar for Tech B
Member Avatar for persianprez

Your question is almost impossible to understand. Is it A, D or Z which has 'value' .8237 ? In your code, you are comparing sorted(dictionary.values()), which is a list, to a float, which is meaningless. Can you explain what you want to do with more details ? If we could …

Member Avatar for Tech B
0
170
Member Avatar for saurav4ever

I think your computer tried to read the file with the shell. You should pass the command [code=text] $ python getsplicefa.py [/code] instead of [code=text] $ ./getsplicefa.py [/code] or perhaps put a line [icode]#!/usr/bin/env python[/icode] at the top of your file.

Member Avatar for Gribouillis
0
323
Member Avatar for octopusgrabbus

You can also make a function [code=python] def gen_args(incoming_data, lnam_fnam, db_date): yield "'A'" for i in list(range(5)) + [4,4]: yield incoming_data[i] for i in range(2): yield lnam_fnam[i] for i in [11, 5, 10] + list(range(12, 18)): yield incoming_data[i] for i in range(2): yield "" yield 0 yield incoming_data[4] yield db_date …

Member Avatar for octopusgrabbus
0
340
Member Avatar for heValbo

If you want to go further, you must write [b]functions[/b] in your program. Here is a function which splits the sentences in a text, assuming that a sentence ends with one or more ".!?". [code=python] import re end_of_sentence = re.compile(r"([\.\!\?]+)") def split_sentences(text): """split_sentences(text) --> list of pairs (sentence, punctuation)""" L …

Member Avatar for heValbo
0
103
Member Avatar for vextorspace

You should have a look at module weakref, which offers WeakValueDictionary and WeakKeyDictionary classes, which could suit your needs. Also consider using a memory profiler like guppy [url]http://guppy-pe.sourceforge.net/[/url] to examine your heap's content.

Member Avatar for Gribouillis
0
107
Member Avatar for AnnetteM

numarray.reshape doesn't apply to python lists. It applies to numarray.NumArray, which is a different type with a specific implementation. You can write [code=python] data2 = numarray.array(data) data3 = numarray.reshape(data2, 5, 91) [/code]

Member Avatar for AnnetteM
0
607
Member Avatar for TotalyWired
Member Avatar for fallopiano

I have another frange function. I remember writing it after reading a discussion about frange functions in the activestate code snippets [code=python] def frange (start ,stop ,n ): """frange(start, stop, n) -> list of n float A range function which returns n equally spaced floating numbers from start to stop""" …

Member Avatar for Gribouillis
0
576
Member Avatar for AnnetteM

You'd better write the datafile line by line to the output file. Here is a way to do it [code=python] #from __future__ import with_statement # <--- uncomment this line if your python is 2.5 import os workDIR = 'C:\\work\\data' # this is a multiline string header = """\ ncols 1422 …

Member Avatar for AnnetteM
0
2K
Member Avatar for bharatk

You are working with a version 0.0.115 beta. You should probably consider using another IDE, unless you want to join the Visual Tkinter team.

Member Avatar for macroasm
0
398
Member Avatar for AnnetteM

This is just a hint [code=python] >>> s = "-9999 -9999 -9999 -9999 0.004537001 0.004537001 0.004537001 " >>> s '-9999 -9999 -9999 -9999 0.004537001 0.004537001 0.004537001 ' >>> s.strip() # remove white space at both ends of s '-9999 -9999 -9999 -9999 0.004537001 0.004537001 0.004537001' >>> s.strip().split() # split s …

Member Avatar for Gribouillis
0
3K
Member Avatar for firstimer04

Here is a way to program this using bitwise operations [code=python] def toi(ps): # convert to integer. Ex "0101" -> 6 return int(ps, 2) def tos(pi): # convert to string. Ex 6 -> "0101" assert(0 <= pi < 16) return bin(16 + pi)[-4:] def and_(ps, qs): pi, qi = toi(ps), …

Member Avatar for Gribouillis
0
90
Member Avatar for gruis

Let the code explain how it works: [code=python] tab = " " * 2 def eds(k,L,s): """ starting with the k-th list in L, adds letters to the current string s """ print("%sentering eds(%d, L, %s)" % (tab*k, k, repr(s))) if k >= len(L): print("%sfound -> %s" % (tab*k, repr(s))) …

Member Avatar for Gribouillis
0
89
Member Avatar for hinz10

If the footer is not too long, you could store it and write it after your data. For example [code=python] f = open("gps.xml", "r+w") f.seek(-sizeoffooter, 2) # go to the beginning of the footer footer = f.read() # store the footer f.seek(-sizeoffooter, 2) # go to the beginning of the …

Member Avatar for Gribouillis
0
96
Member Avatar for herrschteiner

There are [icode]121*120*119*118 = 203889840[/icode] choices for str1, although I don't understand why the digits in str1 need to be different.

Member Avatar for herrschteiner
0
222
Member Avatar for morgan505

[url=http://www.daniweb.com/forums/announcement114-2.html]The solution is here[/url]

Member Avatar for vegaseat
0
116
Member Avatar for dbbd

The list sys.argv contains only strings, not numerical values. So you must convert your argument with [icode]offset = int(sys.argv[1])[/icode]. Python thought you were using the string modulus operator, which has a completely different meaning.

Member Avatar for dbbd
0
258

The End.