473,382 Members | 1,529 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,382 software developers and data experts.

why script work in console window of PyCrust but not work when put it into function?

7
Hi,

I am a Python beginner and using PyCrust to process data for my research work.
I found I not able to import a .py file directly. But I have to type in every lines every time. Or I can save the script in function. Then call out the function in PyCrust. But it's not convenient. And it causes global variable problem.

The case is even I import the numpy lib in the function file.py, but it shows error: “NameError: global name 'append' is not defined” when I call out the function in Pycrust. Could anyone tell me why it shows "append" is not defined even I "import numpy" already?

And how to open the script directly in PyCrust?

Besides, how can I import and export the array with PyCrust ? (As I want to export the array from PyCrust and then run it in the script with SciTE)

Thanks for help.

P.S. The versions I use are:
enthon-python2.4-1.0.0
numpy-1.0.3.1.win32-py2.4


Kanis
Oct 8 '07 #1
6 3572
bartonc
6,596 Expert 4TB
Hi,

I am a Python beginner and using PyCrust to process data for my research work.
I found I not able to import a .py file directly. But I have to type in every lines every time. Or I can save the script in function. Then call out the function in PyCrust. But it's not convenient. And it causes global variable problem.

The case is even I import the numpy lib in the function file.py, but it shows error: “NameError: global name 'append' is not defined” when I call out the function in Pycrust. Could anyone tell me why it shows "append" is not defined even I "import numpy" already?

And how to open the script directly in PyCrust?

Besides, how can I import and export the array with PyCrust ? (As I want to export the array from PyCrust and then run it in the script with SciTE)

Thanks for help.

P.S. The versions I use are:
enthon-python2.4-1.0.0
numpy-1.0.3.1.win32-py2.4


Kanis
Please try using IDLE instead of PyCrust. IDLE will let you save your scripts and run them from the Run menu.
Oct 8 '07 #2
Kanis
7
Please try using IDLE instead of PyCrust. IDLE will let you save your scripts and run them from the Run menu.
Because the interface I using is embedded with PyCrust only. And the data is read in that interface. So if I use IDLE to process the data, I think I have to know how to export the array data first. Do u know how to import and export the array in Python?
Oct 8 '07 #3
bartonc
6,596 Expert 4TB
Because the interface I using is embedded with PyCrust only. And the data is read in that interface. So if I use IDLE to process the data, I think I have to know how to export the array data first. Do u know how to import and export the array in Python?
In that case, PyAlaMode will let you save your files.

Expand|Select|Wrap|Line Numbers
  1. >>> import numpy
  2. >>> a1darray = numpy.zeros(10)
  3. >>> a1darray
  4. array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])
  5. >>> 
Oct 8 '07 #4
Kanis
7
In that case, PyAlaMode will let you save your files.

Expand|Select|Wrap|Line Numbers
  1. >>> import numpy
  2. >>> a1darray = numpy.zeros(10)
  3. >>> a1darray
  4. array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])
  5. >>> 
The interface I use can create a data array called "dataobj" already, then if I want to process the data, I open the embedded "PyCrust" console and the "dataobj" is already defined there. But if I run the Python directly (I mean not use the PyCrust inside the interface), the "dataobj" array is undefined. So, I would like to export the "dataobj" array, let say export it to a file, and then I can read it again when I use the IDLE or other Python Shell or Matlab. How can I export the array into a file?
Oct 8 '07 #5
Kanis
7
In the console (PyCrust), the script works:

>>> def x():
... r = array([1,2,3])
... return r
...
>>> x()
array([1, 2, 3])
------------------------------------------
while I save it as a function named "f()"

import numpy
def f():
r = array([1,2,4])
return r


and call out the function in console, error arouse:

>>> from test_array import f
>>> f()
Traceback (most recent call last):
File "<input>", line 1, in ?
File "C:\Documents and Settings\wckan\My Documents\Python_script\test_array.py", line 3, in f
r = array([1,2,4])
NameError: global name 'array' is not defined

HOW CAN I SOLVED THIS PROBLEM?
Oct 8 '07 #6
bartonc
6,596 Expert 4TB
In the console (PyCrust), the script works:

>>> def x():
... r = array([1,2,3])
... return r
...
>>> x()
array([1, 2, 3])
------------------------------------------
while I save it as a function named "f()"

import numpy
def f():
r = array([1,2,4])
return r


and call out the function in console, error arouse:

>>> from test_array import f
>>> f()
Traceback (most recent call last):
File "<input>", line 1, in ?
File "C:\Documents and Settings\wckan\My Documents\Python_script\test_array.py", line 3, in f
r = array([1,2,4])
NameError: global name 'array' is not defined

HOW CAN I SOLVED THIS PROBLEM?
Expand|Select|Wrap|Line Numbers
  1.  r = numpy.array([1,2,4])
Oct 8 '07 #7

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

Similar topics

0
by: Henk Verhoeven | last post by:
(Reply on this newsgroup to an email - reply by email did not work) Wolfman wrote: > > Hi, > I found your Email in the php Newsgroup. > I was looking for some way to resize some graphiks on my...
0
by: Daniel Joyce | last post by:
When I try and run pycrust, I get... 'import site' failed; use -v for traceback Traceback (most recent call last): File "/usr/bin/pycrust", line 4, in ? from wxPython.lib.PyCrust.PyCrustApp...
8
by: Arun Seetharam | last post by:
Dear Folks, The application I am working on uses Frames (TopFrame, SideFrame(Left) and the MainFrame). On the occurance of a certain event, I am closing the window from one of the frames. This...
2
by: Randell D. | last post by:
Folks, I have got this working before, in part with some help from this ng but I never really understood how I got it working... and last time, I was using it via a popup window as opposed to an...
3
by: niconedz | last post by:
Hi The following code works fine in IE but not Firefox. It's a little script that zooms an image and resizes the window to fit. Can anybody tell me what's wrong? Thanks Nico == btw.....
0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
1
by: Anthony | last post by:
Below is a script I found at http://javascript.internet.com/ for a cascading menu. The script works great but there is one thing that I would like modified. BecauseI am just learning javascript,...
10
by: Stephany Young | last post by:
When one uses the System.Diagnostics.Process.Start method to launch a common or garden Console application, one can set the WindowStyle property of the StartInfo object to ProcessWindowStyle.Hidden...
2
by: Kanis | last post by:
(e.g. a file name g.py with class called "test") evreytime I change the content in test and saved , it will not update my script when I type >>> from g import test But it only work when I...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.