2,646 Posted Topics
Re: There must be something else in your program. In principle, these 2 lines don't send anything to the console. | |
| |
Re: The [icode]i[/icode] in range(0, i + 1, 1) should be [icode]n[/icode]. | |
Re: 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 … | |
Re: 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] | |
Re: 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 … | |
Re: 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] … | |
Re: 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, … | |
Re: You must open the file [code=python] content = open(fileName).read() [/code] | |
Re: Perhaps you should write a command line interpreter. See this code snippet [url]http://www.daniweb.com/code/snippet258640.html[/url] . | |
Re: [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... | |
Re: 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 … | |
Re: If you want to sort by name, you only need to add [icode]scores = sorted(scores)[/icode] after line 4. | |
Re: 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 . | |
Re: 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 … | |
Re: Also see this code snippet [url]http://www.daniweb.com/code/snippet257449.html[/url] . | |
I'm looking for C++ libraries to manipulate real and/or rational polynomials. Does someone know such a library ? | |
Re: It's [code=python] "Please enter a number between %s and %s." % (smallestNum, largestNum) [/code] | |
Re: 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]. | |
Re: On my computer (mandriva linux 2010), the number is not lost when I save as .ps or .pdf. | |
Re: 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 … | |
Re: 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) … | |
Re: 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] | |
Re: 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. | |
![]() | Re: 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 … ![]() |
Re: If you have a 64 bits processor, use a linux system ! Mandriva 2010 gnome is excellent. | |
Re: You can use the code module, which has classes like InteractiveConsole to evaluate python expressions. | |
Re: 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 … | |
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 ! | |
Re: 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 … | |
Re: 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 … | |
Re: 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] | |
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
Re: 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 … | |
Re: 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. | |
Re: 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] | |
Re: What do you want to do with this pseudo code ? | |
Re: 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""" … | |
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
Re: 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), … | |
Re: 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))) … | |
Re: 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 … | |
![]() | Re: 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. ![]() |
Re: [url=http://www.daniweb.com/forums/announcement114-2.html]The solution is here[/url] | |
Re: 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. |
The End.