473,466 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how does a real world program work ?

10 New Member
hello people,
Im have learned python's concepts and can do a fair bit of coding in it. What I'm looking at is to create a real world GUI based program. Of which is plan to create the program text based and then convert it to GUI wxpython.

So before I did go ahead with that I thought of clearing my concepts/doubts:
1) what is the best way to create a program monolithic(Like in the Linux kernel all in one) or like the Micro Kernel (All servers communicating with each other to form a single program or Operating system in the case of the Mach kernel)?

2) Are there any real world examples or open source projects based on the above, which I could be directed towards.?

3) Is creating the programs Text based and then converting to GUI a good way to program ?

4) looking a cross-platform GUI based program, is wxpython the right way to go?

5) When going Menu Driven what function to use to call a file within the same folder to the corresponding choice file.

example:

c:\myprog\mainmenu.py
c:\myprog\menu_option1.py
c:\myprog\menu_option1.py


print "\nMain Menu:"
print "-----------"

# Print out the menu:
print "Please enter choice:"
print "1 - menu_option1"
print "5 - menu_option2"


# The input function both prompts the user for input and fetches it...
input_choice = int(input( "> " ))



if input_choice == 1:
print("menu_option1 choosen")
print("how do i call menu_option2.py")
else:
print("menu_option2 choosen")
print("how do i call menu_option2.py")


Any help would be wonderful. Thanks in advance!
Feb 5 '10 #1
15 1595
d3ph03n1x
10 New Member
Ok! I don't Know if the people who can help have viewed the question or not.

but I'v found my answer to my 5th question, which is:

temp_file_path="c:\\myprog\\menu_option1.py"
temp_file_path="c:\\myprog\\menu_option1.py"



This is how it would be called, though if anyone has a better suggestion it would be appreciated. As this is still static and I'm looking at a dynamic solution.


print "\nMain Menu:"
print "-----------"

# Print out the menu:
print "Please enter choice:"
print "1 - menu_option1"
print "5 - menu_option2"

temp_file_path=""

# The input function both prompts the user for input and fetches it...
input_choice = int(input( "> " ))
temp_file_path="c:\\myprog\\menu_option1.py"
execfile(temp_file_path)


if input_choice == 1:

else:
temp_file_path="c:\\myprog\\menu_option2.py"
execfile(temp_file_path)


Thanks once again!
Feb 5 '10 #2
d3ph03n1x
10 New Member
wow!! I'm shocked 29 Views! Not a single reply.. Neway Thought i should Clarify the 2nd question..

2) Are there any real world examples or open source projects based on the above, which I could be directed towards?

I know/found many on sourceforge but have'nt really found a small simple program/project. which could clear my doubts. And most projects depend on many other projects which makes it even more confusing to keep track of what's actually happening.

Hope this clarification helps!
Thanks! :)
Feb 5 '10 #3
d3ph03n1x
10 New Member
No help ? Surprising! I was under the misconception that I would get a quick and helpful reply.
Feb 6 '10 #4
Glenton
391 Recognized Expert Contributor
I don't know a huge amount about it, but the answer to question 3 is yes! It's the OO way!
Feb 8 '10 #5
Glenton
391 Recognized Expert Contributor
Regarding your question 5, I'm not entirely sure what your specific question is. But the coding can probably be cleaned up a great deal by building up the exec file as follows (BTW please use code tags!!)

Expand|Select|Wrap|Line Numbers
  1. temp_file_path="c:\\myprog\\menu_option"+input_choice+".py"
  2. execfile(temp_file_path)
You may want to check that the input_choice is valid (and I'm assuming it's a string, otherwise you need to do it slightly differently), but probably the GUI will be able to ensure that it is...
Feb 8 '10 #6
d3ph03n1x
10 New Member
Yes Glenton, thanx the answer to Q3 is great, as i shall not be doubtfull anymore. Coming to Q5 that would'nt be the answer I would have been looking for, but then there is always something new to learn! And yes input_choice its a string.

Actually in Q5 what i meant is I have a folder named myprog and within that folder I have 4 files.mainmenu.py, menu_option1.py, menu_option2.py, exit.py. So basically what should be happing is that mainmenu.py is Executed and is displays a menu with 3 options
Expand|Select|Wrap|Line Numbers
  1. 1 - menu_option1.py
  2.            2 - menu_option2.py
  3.            x - exit 
So actually what should be happening is when the user presses "1" and enter, the program executes menu_option1.py which is an individual file in itself, In this way a particular file can be easily be maintained when dealing with large programs.


c:\myprog\mainmenu.py
c:\myprog\menu_option1.py
c:\myprog\menu_option2.py
c:\myprog\exit.py


Expand|Select|Wrap|Line Numbers
  1. input_choice = 1
  2.  
  3.  
  4. while input_choice != 0:
  5.  
  6.  
  7.     print "\n\n\n\n Main Menu:"
  8.  
  9.  
  10. # Print out the menu:
  11.  
  12.     print "Please enter choice:"
  13.     print "1 - menu_option1"
  14.     print "2 - menu_option2"
  15.     print "x - Exit"
  16.  
  17.  
  18. # if i un-tab the below input_choice it goes into an infinite loop
  19. # but is this way it works just how is want it but does not do the executing
  20. # of execfile(file_path) at all, which is not what I'm looking at
  21.  
  22.     input_choice = raw_input( "> " )
  23.  
  24.  
  25.  
  26.  
  27.  
  28. if input_choice == "1":
  29.     print("menu_option1")
  30.     file_path = "C:\\myprog\\menu_option1.py"
  31.     execfile(file_path)
  32.  
  33. elif input_choice == "2":
  34.     print("menu_option2")
  35.     file_path = "C:\\myprog\\menu_option1.py"
  36.     execfile(file_path)
  37. elif input_choice == "x":
  38.     print("Exit")
  39.     file_path = "C:\\myprog\\exit.py"
  40.     execfile(file_path)
  41. else :
  42.     print("That is not a valid option. Please re-enter: ")

Hopefully this should be helpful. Any help would be great!


Thanks in advance!
Feb 8 '10 #7
Glenton
391 Recognized Expert Contributor
Hi

That's what I thought. Again, you can make your code shorter and cleaner here. One thing, is that an infinite loop can be broken out of with the break statement (it's companion is continue, which skips straight to the next cycle in the loop).

So your code could be done like this (by the way thx for putting the code tags in!):
Expand|Select|Wrap|Line Numbers
  1. #set up entry loop
  2. while True:
  3.     print "Please enter choice:"
  4.     print "1 - menu_option1"
  5.     print "2 - menu_option2"
  6.     print "x - Exit"
  7.     input_choice = raw_input( "> " )
  8.     #check code is valid
  9.     if len(input_choice)==1:
  10.         if input_choice in "12x":
  11.             break    
  12.     print "invalid entry"
  13.  
  14. #when you get here, you've got a valid input_choice
  15. if input_choice == "x":
  16.     print("Exit")
  17.     file_path = "C:\\myprog\\exit.py"
  18.     execfile(file_path)
  19. else:
  20.     print("menu_option"+input_choice)
  21.     file_path = "C:\\myprog\\menu_option%s.py"%input_choice
  22.     execfile(file_path)
  23.  
It's not a huge difference, but will be way easier to add menu items to, and is probably easier to maintain.
Feb 8 '10 #8
bvdet
2,851 Recognized Expert Moderator Specialist
I'll weigh in for what it's worth:
1) what is the best way to create a program monolithic(Like in the Linux kernel all in one) or like the Micro Kernel (All servers communicating with each other to form a single program or Operating system in the case of the Mach kernel)?
I don't know how to code like the Linux kernel or an OS, but I would design my program to encapsulate the code and all variables and methods in a series of class objects.

2) Are there any real world examples or open source projects based on the above, which I could be directed towards.?
BitTorrent was originally written in Python. The source code may still be available.

3) Is creating the programs Text based and then converting to GUI a good way to program ?
Yes.

4) looking a cross-platform GUI based program, is wxpython the right way to go?
Tkinter or wxPython would be my choices.

5) When going Menu Driven what function to use to call a file within the same folder to the corresponding choice file.
Why not import your files instead of executing them? Example:
Expand|Select|Wrap|Line Numbers
  1. import module1
  2. import module2
  3.  
  4. if option == "1":
  5.     obj = module1.Class1(args)
  6. elif option == "2":
  7.     obj = module2.Class1(args)
Feb 8 '10 #9
Glenton
391 Recognized Expert Contributor
I would definitely agree with bvdet that importing and using classes is superior!
Feb 9 '10 #10
d3ph03n1x
10 New Member
@Glenton & @bvdet Thank you so much for the help.

@bvdet I have found the Bittorrent Source (BitTorrent-5.3-GPL), is it the correct source? or should I be looking for older code ? If so a link would b great. Though if correct, its still going to be very helpful though would be a bit lengthy.

When I import the modules is it necessary that the file stays with the same folder where the main file is? its not a compulsion, I was just thinking if its possible.

can i have them as below:

Expand|Select|Wrap|Line Numbers
  1. c:\myprog\data_arranged\menu_option1.py
  2. c:\myprog\data_arranged\menu_option2.py
  3. c:\myprog\data_arranged\exit.py
  4. c:\myprog\main_menu.py

Where main_menu.py is the file that is run and menu_option1.py, menu_option.py, exit.py get imported.

Thanks once again! :)
Feb 10 '10 #11
Glenton
391 Recognized Expert Contributor
Look at these docs, in particular 6.1.2 which talks about the path (where you can put modules that will always be accessible) and 6.4 which talks about packaging modules within subdirectories.

Let us know how it goes...
Feb 11 '10 #12
d3ph03n1x
10 New Member
Thanks Glenton! Helpful docs. I will stick to the simple importing for the moment. I do have an issue which i'm not sure how to tackle.

Expand|Select|Wrap|Line Numbers
  1. # define class to add contact
  2. class add_cont:
  3.     def addcontact(self):
  4.         fname=raw_input("First Name: ")
  5.         lname=raw_input("Last Name: ")
  6.         address=raw_input("Address: ")
  7.         phone=raw_input("Phone No: ")
  8.         mobile=raw_input("Mobile: ")
  9.  
  10.  
  11.         print("\n\nInfomation Entered: \n")
  12. #print the Info just enterd
  13.         print("Name: "+fname+" "+lname+"\n"+"Address: "+address+"\n"+"Phone: "+phone+"\n"+"Mobile: "+mobile+"\n")
  14.  
  15. #If correct user saves if not user re-enters data or edits
  16.         print("Do you want to save Information?\n")
  17.  
  18. #print("Y(yes) or N(no)\n")
  19.  
  20.         answer=raw_input("Y(yes) or N(no)\n\n:>")
  21.  
  22.  
where do i check is the answer is yes or know ? And when I try to check within the method it says invalid syntax, secondly either the user would enter "y"||"Y" for yes and "n"||"N" for no. How do i check that as well within the if-else statement. Cause I apply c++ logic and get very confused.

Expand|Select|Wrap|Line Numbers
  1. #within the menu this is what happens
  2. import add_contact
  3. contobj=add_cont()
  4.  
  5. #And when user chooses menu_option1(Add contact)
  6.  
  7. #which calls the add contact class and gets the input from the user and verifies
  8. #from user and saves or re-inputs data to a file/mysql database 
  9. contobj.addcontact()
  10.  
  11.  
  12.  
  13.  
Thanks once again :)
Feb 13 '10 #13
Glenton
391 Recognized Expert Contributor
Hi

See this post for a method for verification (towards the bottom).

I'd be inclined to do this kind of verification *before* passing the data across to the class.

Your class is not right, either, BTW. Rather than an "add_contact" class, make it just a "contact" class. Think nouns not verbs for classes!!

Then it needs to be self.whatever = whatever in the __init__ method to change the variable attached to the actual class.

Again, telling us what you're trying to achieve is always a better way to get better answers (along with what you've tried, which you gave us).

It's probably also better to start a new post for a new idea...

Good luck

G
Feb 14 '10 #14
Glenton
391 Recognized Expert Contributor
BTW, for databases, I often use a dictionary of numpy arrays. Very versatile.
Feb 14 '10 #15
d3ph03n1x
10 New Member
Ok Glenton as per your suggestion I'll be starting new Topics for individual issues in the future. Btw I'm learning python as my personal learning curve. And no this is not Home Work. :)

Though What I'm trying to do is create a Simple contact list, with a menu, which i would add contacts too, edit contacts, view them, and search them when there is a long list, maybe on the basis of contact numbers or names. And first start with saving them in a file. Then once i have that functioning correctly. Either use the text file as a temp dump to update the database. Or if that's not possible or not the correct way to go about the solution, then would directly connect it to the database.
Once successful I shall start adding the GUI interface to the program.

BTW can you guide to any simple tutorials on using numpy as per you suggestion ?
Feb 15 '10 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Rene Pijlman | last post by:
Section 6.5 "What is delegation?" of the FAQ says: "Python programmers can easily implement delegation. For example, the following class implements a class that behaves like a file but converts...
30
by: Christian Seberino | last post by:
How does Ruby compare to Python?? How good is DESIGN of Ruby compared to Python? Python's design is godly. I'm wondering if Ruby's is godly too. I've heard it has solid OOP design but then...
44
by: Bamber | last post by:
Why does f get returned ? (compiled with gcc). #include<stdio.h> int func(int a); main() { int f; f=func(7); printf("f=%d",f);
34
by: Guch Wu | last post by:
Boost has many terrific libraries. But I want to know whether they are ready for using in real projects. Which of them are mature enough, or just only in progress?
4
by: Henry | last post by:
Does anybody have a real-world sample of buiding a treeview control using data from database tables? All the sample code I have found either builds the treeview manually or uses a file directory...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
130
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
14
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
29
by: zzuse | last post by:
I have been working in one company for nearly one year as a c programmer.I want to write more codes to improve my programming skills.But I found my work was just change some configuration files ....
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.