473,378 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

import doesn't work as i want

Hello,

In the botom of this post you will see my source code.

The problem is when i launch main.py that doesn't make anything why ?

Thanks
olivier noblanc
Atousoft
http://www.logiciel-erp.fr

I have main.py :

---------------------------------
import wx
import inc.importlist
----------------------------------

inc/importlist.py
------------------------------------
import wx.grid
import getdata
import time
import sys
-----------------------------------

inc/wxgrid.py
-------------------------------------
# -*- coding: cp1252 -*-
#starta = time.time()
import wx
import getdata

class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.grid_1 = wx.grid.Grid(self, -1, size=(1, 1))

self.__set_properties()
self.__do_layout()
# end wxGlade

def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("frame_1")
self.SetSize((400, 400))
# end wxGlade

self.grid_1.CreateGrid(len(db.data), len(db.fields))

# met les labels des colonnes
index = 0
for item in db.fields:
self.grid_1.SetColLabelValue(index, item[0])
index += 1

# remplissage des données.
for row in range(len(db.data)):
for col in range(len(db.data[row])):
values = db.data[row][col]
self.grid_1.SetCellValue(row,col,str(values))

# mise en forme et affichage
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(self.grid_1, 1, wx.EXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
self.Layout()
# end wxGlade

# end of class MyFrame
if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
#startb = time.time() - starta
#print startb
app.MainLoop()
---------------------------------------

inc/getdata.py
----------------------------------------------
import MySQLdb
class Eb_db:
def __init__(self):
try:
connection = MySQLdb.connect(host="dellced", user="ats",
passwd="", db="atsmedicdatabase" )
cursor = connection.cursor()
cursor.execute( "SELECT * FROM PATIENT " )
except MySQLdb.OperationalError, message:
errorMessage = "Error %d:\n%s" % ( message[ 0 ], message[ 1 ] )
return
else:
self.data = cursor.fetchall()
self.fields = cursor.description
cursor.close()
connection.close()
-----------------------------------------


Jul 18 '05 #1
4 1799
Olivier Noblanc wrote:
In the botom of this post you will see my source code.

The problem is when i launch main.py that doesn't make anything why ?


the "if __name__" statement checks the name of the module. if you run
Python file as a script, by passing a filename to the python interpreter, the
__name__ variable is set to "__main__". if you import a file as a module,
the __name__ is the name of the module, not "__main__".

if you want main.py to do something, move that code to main.py (or move
it into a function, and call it from main.py)

</F>

Jul 18 '05 #2
how to move in function ?

"Fredrik Lundh" <fr*****@pythonware.com> a écrit dans le message de news:
ma***************************************@python.o rg...
Olivier Noblanc wrote:
In the botom of this post you will see my source code.

The problem is when i launch main.py that doesn't make anything why ?


the "if __name__" statement checks the name of the module. if you run
Python file as a script, by passing a filename to the python interpreter,
the
__name__ variable is set to "__main__". if you import a file as a
module,
the __name__ is the name of the module, not "__main__".

if you want main.py to do something, move that code to main.py (or move
it into a function, and call it from main.py)

</F>

Jul 18 '05 #3
Olivier Noblanc wrote:
how to move in function ?


how to put code in a function? the same way you put code in a method.

change

if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
#startb = time.time() - starta
#print startb
app.MainLoop()

to

def main():
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
#startb = time.time() - starta
#print startb
app.MainLoop()

and call it from your main program:

import inc.wxgrid
inc.wxgrid.main()

if you have trouble sorting out the imports, this might help:

http://docs.python.org/ref/import.html
http://www.python.org/doc/essays/packages.html
http://effbot.org/zone/import-confusion.htm

</F>

Jul 18 '05 #4
On Mon, Jan 31, 2005 at 04:52:24PM +0100, Olivier Noblanc ATOUSOFT wrote:
Hello,

In the botom of this post you will see my source code.

The problem is when i launch main.py that doesn't make anything why
?


I'm guessing you don't have an __init__.py in inc/

--
John Lenton (jo**@grulic.org.ar) -- Random fortune:
/* now make a new head in the exact same spot */
-- Larry Wall in cons.c from the perl source code

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFB/58QgPqu395ykGsRAttQAJ9Ty+lytzr9Nlz+UZZTN3W0bCfVQAC dHhIh
ULhyExDNjL491Uh++eLGyqI=
=TsBl
-----END PGP SIGNATURE-----

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Manlio Perillo | last post by:
Hi. I'm a new user of Python but I have noted a little problem. Python is a very good language but it is evolving, in particular its library is evolving. This can be a problem when, ad example,...
3
by: Olivier Noblanc ATOUSOFT | last post by:
Hello, When i want to import a .py fire from another subdirectory i make import inc/setupxml but that make me an error message.
1
by: Stephen Edgecombe | last post by:
Hi Environment: Visual Studio .NET 2003 (vb) I am developing an XSD Schema and want to include some building blocks from another source, so they have a different namespace. - If I use an...
1
by: KS | last post by:
Hi, I have creatd a custom Outlook form with a few custom form fields. When completed the form is sent to me and goes into my Inbox. This works fine. Now Iam trying to write some code in...
23
by: Shane Hathaway | last post by:
Here's a heretical idea. I'd like a way to import modules at the point where I need the functionality, rather than remember to import ahead of time. This might eliminate a step in my coding...
3
by: Chris | last post by:
Hi, 1) In file test.aspx, i put: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %> <%@ import namespace="System.Data"%> <%@ import...
7
by: Ron Adam | last post by:
from __future__ import absolute_import Is there a way to check if this is working? I get the same results with or without it. Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win 32 ...
49
by: Martin Unsal | last post by:
I'm using Python for what is becoming a sizeable project and I'm already running into problems organizing code and importing packages. I feel like the Python package system, in particular the...
2
by: WP | last post by:
Hello, I've just started to work with DB2 (using the express edition version 9.5 under windows vista) and I'm accessing it through a java program (my java's very rusty). The java program loads the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.