473,795 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing


Greetings,

First I will admit I am new to Python but have experience with C++ and
some Tcl/Tk. I am starting to use a tool called MaxQ that uses
jython. I have been studying Rossum's tutorial but still am unclear on
importing, the use of self, and calling functions with their own name
in quotes. In the code below the lines between #Start and #End are
generated by browsing web pages. In a large test this section can
become quite large. The maxQ documentation suggests breaking it up
into functions. If so could these functions be placed in a separate
file and imported? Is it acceptable to import into a class? If
imported as a function will self as used here need to be changed?
Would it be better to duplicate class and import whole classes?

Any suggestions will be appreciated, especially other Python
tutorials.

Best Regards,

jh

~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~

# Generated by MaxQ
[com.bitmechanic .maxq.generator .JythonCodeGene rator]
from PyHttpTestCase import PyHttpTestCase
from com.bitmechanic .maxq import Config
global validatorPkg
if __name__ == 'main':
validatorPkg = Config.getValid atorPkgName()
# Determine the validator for this testcase.
exec 'from '+validatorPkg+ ' import Validator'
# definition of test class
class MaxQTest(PyHttp TestCase):
def runTest(self):
self.msg('Test started')

#Start

self.msg("Testi ng URL: %s" % self.replaceURL ('''http://
www.dogpile.com/'''))
url = "http://www.dogpile.com/"
params = None
Validator.valid ateRequest(self , self.getMethod( ), "get", url,
params)
self.get(url, params)
self.msg("Testi ng URL: %s" % self.replaceURL ('''http://
www.dogpile.com/favicon.ico''') )
url = "http://www.dogpile.com/favicon.ico"
params = None
Validator.valid ateRequest(self , self.getMethod( ), "get", url,
params)
self.get(url, params)

#End

# ^^^ Insert new recordings here. (Do not remove this line.)
# Code to load and run the test
if __name__ == 'main':
test = MaxQTest("MaxQT est")
# test.Run() #Either of these two lines work equally well.
test.runTest() #I suspect that Run() is a method of
PPyHttpTestCase or a builtIn

Mar 16 '07 #1
2 1365
HMS Surprise a écrit :
Greetings,

First I will admit I am new to Python but have experience with C++ and
some Tcl/Tk. I am starting to use a tool called MaxQ that uses
jython. I have been studying Rossum's tutorial but still am unclear on
importing,
What's your problem here ?
the use of self,
In Python, a method is a wrapper around a function. This wrappers as a
reference to the instance on which the method is called, and calls the
wrapped function passing the instance as first argument. By convention,
it's named 'self', but technically you could use any other name. So, to
make a long story short:
- you need to declare 'self' as the first argument of a method
- you need to use self to access the current instance within the
method body
- you *don't* have to pass the instance when calling the method
and calling functions with their own name
You mean the
test = MaxQTest("MaxQT est")
line ?

First point: it's not a function call, it's an object instanciation.
There's no 'new' keyword in Python, classes are callable objects acting
as factory for their instances.

Second point: passing the name of the class here is specific to MaxQ,
and I'd say it's only used for internal and display stuff.
in quotes. In the code below the lines between #Start and #End are
generated by browsing web pages. In a large test this section can
become quite large. The maxQ documentation suggests breaking it up
into functions. If so could these functions be placed in a separate
file and imported?
Yes, but you'd have to bind them to the class manually (cf below).
Is it acceptable to import into a class?
Yes, but this wont solve your problem. Import creates a module object in
the current namespace, that's all.
If
imported as a function will self as used here need to be changed?
Nope.

def quux(self, foo):
self.bar += foo

class Boo(object):
def __init__(self, bar):
self.bar = bar

Boo.quux = quux
b = Boo(40)
b.quux(2)
print b.bar

Mar 16 '07 #2
Thanks for posting. I continued to read and realized the instantiation
was not a function call soon after I posted. Oh well...

Still unsure about the best way to break up the large #start - #end
section. I appreciate your answers and try to digest them more fully.
Then maybe I will have a better idea and can post better qualified/
quantified questions.

Thanks again,

jh

Mar 16 '07 #3

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

Similar topics

12
2407
by: qwweeeit | last post by:
The pythonic way of programming requires, as far as I know, to spread a big application in plenty of more manageable scripts, using import or from ... import to connect the various modules. In some cases there is a further complication: module importing through an indirect mechanism, like: exec "from " + xxx + " import *". A part the fact that I have not understood the "real" difference between import and from ... import (or also from......
4
2668
by: jean-marc | last post by:
As an application programmer, I'm not well versed in the material aspects of computing (memory, cpu, bus and all). My understanding of imports in Python is such: the __main__ program is the center piece which holds the programs reference: globals, functions, classes, modules etc. The objects of this file (functions and classes) are directly accessible; 'import suchModule' s objects are attainable through the *qualified name*...
11
3419
by: Grim Reaper | last post by:
I am importing a .csv file into Access that has 37 fields. My problem is that sometimes the last field only has data at the end of the column (it looks like when you import a file into Access, for the last field, it only checks the top few 'cells' to see if there is any data, if not, the field is not imported). How do I 'force' Access to import the field, regardless if there is data in the top of the field or not? For instance, I might...
7
3308
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte buffer into the character pointer. The code looks like the following: #include <stdio.h> #include <stdlib.h> #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call,
3
1803
by: rs387 | last post by:
Hi, I've found the following behaviour on importing a variable from a module somewhat odd. The behaviour is identical in Python 2.5 and 3.0b2. In summary, here's what happens. I have a module, oddmodule.py (below), that defines a variable, OddVariable, by assigning a value A to it. The file I execute, mainfile.py, imports and re-binds OddVariable to a value B. I have two test modules which import the
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.