4,305 Posted Topics

Member Avatar for katharnakh

I took a cursory look at your code and made some suggestion, at least managed to give you a way to connect between classes. Normally you would use inheritance to share attributes, but in this case it is difficult because you also inherit wxClasses and they will give you collisions …

Member Avatar for vegaseat
0
202
Member Avatar for mruane

Oh no, friends() is a function call! You would have to do something like this ... [code=python]def friends(): friends1 = raw_input().lower() # I guess friends() doesn't call this? if friends1 == "yes": part_two() elif friends1 == "no": print "Yeah I figured that much." part_two_a1() else: print "Come on, it's a …

Member Avatar for Mouche
0
114
Member Avatar for mruane

Are you using Windows98 or Windows ME operating system on your computer? Also, are you using unicode characters? That would be the only time you would have to worry about Unicows.dll. It is actually in the Python24 folder. Unicows.dll is the Unicode Layer DLL for Windows 9x and ME (Windows …

Member Avatar for mruane
0
148
Member Avatar for macca1111

This shows you a more streamlined way to read in and process your file ... [code=python]str1 = """'name1 surname',1,0,0,0,0 'name2 surname',0,1,1,0,0 """ # create the test file fout = open("file.txt", "w") fout.write(str1) fout.close() names = [] # now read it in a line at a time for line in open("file.txt", …

Member Avatar for vegaseat
0
136
Member Avatar for sneekula
Member Avatar for jbennet
0
232
Member Avatar for Gorilla

My personal suspicion is that Py2Exe does not handle Jython, otherwise it would be called Jy2Exe. Can you copy module javax.swing into the dist folder and try to run the executable again?

Member Avatar for bumsfeld
0
179
Member Avatar for sneekula

When I first looked at this problem, I thought it would be very simple routine stuff. To my surprise this thing is loaded with programming possibilities. [php]# reverse integer digit by digit, the long way ... x = 12345 x_string = str(x) # "12345" x_list = list(x_string) # ['1', '2', …

Member Avatar for ghostdog74
0
466
Member Avatar for macca1111

I still don't understand your file structure or the reason for a file. Will this help ... [code=python]import random def show_hand(hand): """give drawn cards more detailed descriptions and then display""" for item in hand: rank = item[0] suit = item[1] if rank == 1: rank = "Ace" elif rank == …

Member Avatar for macca1111
0
183
Member Avatar for mruane

Here is an example I was thinking of. Don't create global variables, just pass to and from your functions as needed ... [php]import random import time def delay(seconds): time.sleep(seconds) def shuffle_hitlists(my_hitlist, mo_hitlist): """shuffle the two lists and return the result""" random.shuffle(my_hitlist) random.shuffle(mo_hitlist) return my_hitlist, mo_hitlist def battle(my_hitlist, mo_hitlist, my_strength, mo_strength): …

Member Avatar for vegaseat
0
112
Member Avatar for katharnakh

Your problem is similar to one just discussed. You are adding a sizer object to a sizer object. That will lead to runtime errors. Look at Ene Uran's comments here: [url]http://www.daniweb.com/techtalkforums/post269933-2.html[/url]

Member Avatar for vegaseat
0
144
Member Avatar for macca1111

You could handle your cards in the form of a list of (rank, suit) tuples which can be sorted easily by rank or suit, just take a look at the Python code snippet at: [url]http://www.daniweb.com/code/snippet568.html[/url] I assume your card file is a limited number of cards, not the whole deck?

Member Avatar for macca1111
0
107
Member Avatar for macca1111

Just a note, function names like __str__, __repr__, __cmp__ have a special meaning in Python, do not use them for your class methods unless you want them to fullfill this special purpose.

Member Avatar for macca1111
0
317
Member Avatar for macca1111

For how to show the card as an image take a look at: [url]http://www.daniweb.com/techtalkforums/post257347-78.html[/url] This example uses the Tkinter canvas and the canvas.create_image() function.

Member Avatar for Zonr_0
0
1K
Member Avatar for mruane

Define/create all your functions before you call [INLINECODE]denaystart()[/INLINECODE], which starts your program. Functions are called with the parenthesis, even if they are empty. The way you have written your code right now [INLINECODE]denaystart()[/INLINECODE] is called, and therefore [INLINECODE]prompt_login()[/INLINECODE], before [INLINECODE]prompt_login()[/INLINECODE] has been defined.

Member Avatar for vegaseat
0
155
Member Avatar for DarkFlash

Welcome to the DaniWeb Python Forum! If you are familiar with programming, then the Python Cookbook is loaded with good code segments: [url]http://aspn.activestate.com/ASPN/Cookbook/Python[/url]

Member Avatar for DarkFlash
0
278
Member Avatar for sneekula

If you wanted to use the digits of an integer, you could convert to a string like mawe suggested and then use the indexed string elements ... [code]x = 12345 s = str(x) print s[0] # 1 print s[1] # 2 print s[2] # 3 print s[4] # 5 print …

Member Avatar for sneekula
0
121
Member Avatar for mruane

Interesting project! Looks like you have to get familiar with the time, datetime and calendar modules. You also might have to google for the medical facts. Good idea though!

Member Avatar for vegaseat
0
88
Member Avatar for Mouche

Zonr is right, that is what a tuple is for! You want to preserve the integrity of your data here.

Member Avatar for vegaseat
0
141
Member Avatar for mruane

I think Ene added the code tags thing as a reminder so your indentation show properly in the forum posts. Thanks for using them so judiciously! I have to think about the battle with a monster. You could use two lists of hitpoints, that you could shuffle at the start. …

Member Avatar for vegaseat
0
173
Member Avatar for Mouche

These are used to override external functions/methods, for example: [php]# example of methods you can override in classes class Dollars(object): def __init__(self,amount): self.amount = amount def __repr__(self): return '$%.2f' % self.amount def __str__(self): return '"%s"' % str(self.amount) a = Dollars(10) print a # 10 print "The amount is", a # …

Member Avatar for Mouche
0
108
Member Avatar for Mouche

Something like main() makes for cleaner code, a little extra work. I should use it more often.

Member Avatar for vegaseat
0
137
Member Avatar for Mouche

[php]alpha_list.count(c) [/php]... simply counts the number of times c is in the list. If the count < 1 then it isn't present yet and you can append the list.

Member Avatar for vegaseat
0
164
Member Avatar for HLA91

It is ... [code]import time # some of your code here ... time.sleep(2) # ... more code [/code]... or you can use ... [code]from time import sleep sleep(2) [/code]

Member Avatar for vegaseat
0
178
Member Avatar for sneekula

Yes, I would say avoid globals like a pest! They are used by folks familiar with C/C++ programming, where passing arguments, particularly multiple arguments are a possible pointer nightmare. Here is an example where a global might be useful ... [php]x = 0 def incr_x() : """here x changes, so …

Member Avatar for jrcagle
0
142
Member Avatar for cancer10

There is a thread called "Starting Python" just above or near this one. Give it a try! Python is available for many different Operating Systems, so you have to make sure you are downloading and installing the right version. Hope you get inspired with Python. It is a relatively easy …

Member Avatar for HLA91
0
219
Member Avatar for HLA91

A short code to show PYTHONPATH ... [code]# show the system path for Python --> PYTHONPATH import sys print "These are the directories Python looks into for modules and source files:" for folder in sys.path: print folder print "-"*30 # print 30 dashes print "This would be your present working …

Member Avatar for vegaseat
0
198
Member Avatar for HLA91

Notice that raw_input() returns a string, so you have to put Harry in quotes ... [code]name = raw_input ("Please enter your name: ") if name == "Harry": print "Welcome" else: print "You smell" [/code]

Member Avatar for vegaseat
0
164
Member Avatar for sneekula

Here is a case where you don't know exactly how many arguments you will be passing to a Python function: [php]# explore the argument tuple designated by *args # used for cases where you don't know the number of arguments def sum_average(*args): size = len(args) sum = 0 for k …

Member Avatar for vegaseat
0
275
Member Avatar for sneekula

On Windows right click on the IDLE icon and select Properties. Edit the "Start in:" information to the folder you want to have, then apply. That should do it!

Member Avatar for sneekula
0
111
Member Avatar for sneekula

I took the liberty to use x and y so you can see the key:value difference in the Python internal globals dictionary ... [php]x = "xrange(1, 5)" print x # xrange(1, 5) print type(x) # <type 'str'> string named xrange print list(x) # ['x', 'r', 'a', 'n', 'g', 'e', '(', …

Member Avatar for sneekula
0
95
Member Avatar for vegaseat

I am trying to post a Python code snippet and get this: [QUOTE]vegaseat, you do not have permission to access this page. This could be due to one of several reasons: Your user account may not have sufficient privileges to access this page. Are you trying to edit someone else's …

Member Avatar for Dani
0
201
Member Avatar for venomlash

[QUOTE=iamthwee;263953]Best stick with && instead of "and" as you'll encounter problems if you switch compilers.[/QUOTE] Again, it depends on which country you live in. Not all keyboards have a & key!!!! Actually "and" looks a lot more readable than "&&". Dev-C++ uses a much more international open source GNU compiler. …

Member Avatar for vegaseat
0
202
Member Avatar for Line

Are you trying to printf() a double into an integer format specifier %d? You could cast to an integer, but it looks like you are flirting with the integer size limits.

Member Avatar for Line
0
202
Member Avatar for katharnakh

I have not used the Microsoft Excel data extractor module, but I know it will not work with password protected spreadsheets. That could be the problem. Also sudhir, it would be nice if you could display some of your code.

Member Avatar for vegaseat
0
340
Member Avatar for mruane

Take a look at the sticky above called "Starting Python". It does some hand holding. You learn Python best by writing code, simple at first then more complex. The idea of this forum is to ask questions when you need help. Start your thread with the proper title, this way …

Member Avatar for bumsfeld
0
113
Member Avatar for Mouche

Might be a little much to digest, but here it is ... [php]# when you set up variables like ... book = "Python for Nuts" pages = 223 scripts = 77 # Python keeps this information in a local dictionary called up with vars() print vars() # { ... , …

Member Avatar for Mouche
0
150
Member Avatar for Matt Tacular

Start learning C++, I am sure it will make it easy to do the things you want to do! What will the parallel port go to? Our friends in the C++ forum will be a lot of help! You can also look into PySonic and Fmod.

Member Avatar for vegaseat
0
128
Member Avatar for Mouche

For the person that thinks C is so much more powerful than Python, give this small problem to solve in C. The Python code is here ... [code]# split a text string into its words and sort the words ... text = "explain to me why C is so much …

Member Avatar for jrcagle
1
3K
Member Avatar for shadowmoon

PlaySound() does not play midi files, use mciSendString() to play a midi music file. Check the details in cpp code snippet: [url]http://www.daniweb.com/code/snippet118.html[/url]

Member Avatar for andor
0
485
Member Avatar for chicagoavonlady

Take a look at function fscanf() that delimits on whitespaces. Nothing wrong with using it in C++, it is part of ANSI C++.

Member Avatar for chicagoavonlady
0
111
Member Avatar for dunderhead

I am throwing this in for the inquisitive amongst you ... [php]class Static(object): k = 0 # classmethod decorator allows you to simply call Static.count() @classmethod def count(self): self.k += 1 return self.k print Static.count() # 1 print Static.count() # 2 print Static.count() # 3 [/php]

Member Avatar for dunderhead
0
2K
Member Avatar for FireSBurnsmuP

Good insight by Ene here! One additional comment, Python is object oriented, but unlike Java, the use of OOP is optional. The major problem with Python is its relative newness. The entrenched computer-science teaching staff of many institutes of higher learning is used to teaching C++ or Java, not-so-new languages …

Member Avatar for vegaseat
0
179
Member Avatar for bumsfeld

I remember that the Windows OS had over 36,000 bugs at one time, and only a portion of them got fixed. The problem is that the more complex a program gets the more bugs it will have, and that fixing one bug can create two new ones. Thanks to Jeff …

Member Avatar for nytrokiss
0
269
Member Avatar for zac_haryy

You are declaring functions residential_rate(), commercial_rate(), industrial_rate() also as floats of the same name in function main(). Remove those variables and it will work! Oops, I was too slow! Sorry Mister Dragon near St Louis!

Member Avatar for zac_haryy
0
102
Member Avatar for tlly

I like to do simple C++ things ... [code]// split a string into its words and load them into a vector #include <cstring> // for strtok()? #include <iostream> #include <vector> using namespace std; int main() { char str[] = "This is a sample string."; char *pch; char delimiter[] = " …

Member Avatar for WaltP
0
107
Member Avatar for shermaine

[QUOTE=~s.o.s~;259013]Try something like: [code] int counter = 1 ; while (counter <= 4 ) { printf ("Enter the weight %d: ", counter) ; scanf ("%d", &my_weight [counter - 1] ) ; if ( some_condition_of_validity) { counter ++ ; } else { printf ("Incorrect choice!!!") ; } } [/code] This should …

Member Avatar for vegaseat
0
173
Member Avatar for jrcagle
Member Avatar for LieAfterLie

If you are using Windows and Dev-C++ then the function is Sleep(milliseconds) ... [code]#include <cstdlib> #include <iostream> #include <windows.h> // needed for Sleep(millisec) using namespace std; int main(int argc, char *argv[]) { cout << "start..." << endl; Sleep(2000); cout << "done..." << endl; system("PAUSE"); return EXIT_SUCCESS; } [/code]

Member Avatar for LieAfterLie
0
554
Member Avatar for LieAfterLie

Hidden in the DaniWeb C++ code snippets is an example of using WinAPI SetPixel() that allows you to put a pixel at the specified x,y coordinates, and also uses the color you give it. The example shows a sine wave, but as long as your mathematics holds out, you can …

Member Avatar for LieAfterLie
0
106
Member Avatar for etxulid
Member Avatar for vegaseat
0
219

The End.