473,841 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is wrong with my code?

import cPickle, shelve

could someone tell me what things are wrong with my code?

class progress:

PROGRESS_TABLE_ ACTIONS=["new","remove", "modify"]
DEFAULT_PROGRES S_DATA_FILE="pr ogress_data"
PROGRESS_OUTCOM ES=["pass", "fail"]
def unpickleProgres sTable(pickled_ progress_data_f ile):

return unpickled_progr ess_table

def pickleProgressT able(progress_t able_to_pickle) :

return pickled_progres s_data_file

# Of course, you get progress_table is unpickled progress table.
def progressTable(p rogress_table, action, task, pid=len(progres s_table), outcome=PROGRES S_OUTCOMES[1]):
pid_column_list =progress_table[0]
task_column_lis t=progress_tabl e[1]
outcome_column_ list=progress_t able[2]

# But a task must also come with an outcome!
def newEntry(new_ta sk, new_outcome):
new_pid=len(tas k_column_list)

pid_column_list .extend(new_pid )
task_column_lis t.extend(new_ta sk)
outcome_column_ list.extend(new _outcome)

def removeEntry(pid _to_remove, task_to_remove) :

if pid_column_list .index(pid_to_r emove)==task_co lumn_list.index (task_to_remove ):
# Must remove all columns for that task
index_for_remov al=pid_column_l ist.index(pid_t o_remove)

pid_column_list .remove(index_f or_removal)
task_column_lis t.remove(index_ for_removal)
outcome_column_ list.remove(ind ex_for_removal)

# Default action is to modify to pass
def modifyEntry(pid _to_modify, outcome_to_modi fy=PROGRESS_OUT COMES[0]):
index_for_modif ying=pid_column _list.index(pid _to_modify)

# Modify the outcome
outcome_column_ list[index_for_modif ying]=outcome_to_mod ify
Dec 20 '06 #1
9 2132
It is hard to determine what is wrong with your code without you
telling anyone why it is you believe something is wrong with it. Did
you get an exception? Did it simply not do what it was expected to do?
There seems to be some apparent indenting problems, but maybe that is
just from pushing it through the e-mail. I see some general stylistic
problems as well, but without know what you are actually asking, I
won't know what questions to answer. "What is wrong with my code?" is
a container of many many smaller questions, and you need to focus your
questions better.

On 21 Dec 2006 09:16:58 +1100, Pyenos <py****@pyenos. orgwrote:
import cPickle, shelve

could someone tell me what things are wrong with my code?

class progress:

PROGRESS_TABLE_ ACTIONS=["new","remove", "modify"]
DEFAULT_PROGRES S_DATA_FILE="pr ogress_data"
PROGRESS_OUTCOM ES=["pass", "fail"]
def unpickleProgres sTable(pickled_ progress_data_f ile):

return unpickled_progr ess_table

def pickleProgressT able(progress_t able_to_pickle) :

return pickled_progres s_data_file

# Of course, you get progress_table is unpickled progress table.
def progressTable(p rogress_table, action, task, pid=len(progres s_table), outcome=PROGRES S_OUTCOMES[1]):
pid_column_list =progress_table[0]
task_column_lis t=progress_tabl e[1]
outcome_column_ list=progress_t able[2]

# But a task must also come with an outcome!
def newEntry(new_ta sk, new_outcome):
new_pid=len(tas k_column_list)

pid_column_list .extend(new_pid )
task_column_lis t.extend(new_ta sk)
outcome_column_ list.extend(new _outcome)

def removeEntry(pid _to_remove, task_to_remove) :

if pid_column_list .index(pid_to_r emove)==task_co lumn_list.index (task_to_remove ):
# Must remove all columns for that task
index_for_remov al=pid_column_l ist.index(pid_t o_remove)

pid_column_list .remove(index_f or_removal)
task_column_lis t.remove(index_ for_removal)
outcome_column_ list.remove(ind ex_for_removal)

# Default action is to modify to pass
def modifyEntry(pid _to_modify, outcome_to_modi fy=PROGRESS_OUT COMES[0]):
index_for_modif ying=pid_column _list.index(pid _to_modify)

# Modify the outcome
outcome_column_ list[index_for_modif ying]=outcome_to_mod ify
--
http://mail.python.org/mailman/listinfo/python-list

--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
Dec 20 '06 #2
Pyenos wrote:
could someone tell me what things are wrong with my code?
do you want a free code review, or do you have problems with the code
and just forgot to mention what they are?

</F>

Dec 20 '06 #3
"Calvin Spealman" <ir********@gma il.comwrites:
It is hard to determine what is wrong with your code without you
telling anyone why it is you believe something is wrong with it. Did
you get an exception? Did it simply not do what it was expected to do?
There seems to be some apparent indenting problems, but maybe that is
just from pushing it through the e-mail. I see some general stylistic
problems as well, but without know what you are actually asking, I
won't know what questions to answer. "What is wrong with my code?" is
a container of many many smaller questions, and you need to focus your
questions better.

On 21 Dec 2006 09:16:58 +1100, Pyenos <py****@pyenos. orgwrote:
import cPickle, shelve

could someone tell me what things are wrong with my code?

class progress:

PROGRESS_TABLE_ ACTIONS=["new","remove", "modify"]
DEFAULT_PROGRES S_DATA_FILE="pr ogress_data"
PROGRESS_OUTCOM ES=["pass", "fail"]
def unpickleProgres sTable(pickled_ progress_data_f ile):

return unpickled_progr ess_table

def pickleProgressT able(progress_t able_to_pickle) :

return pickled_progres s_data_file

# Of course, you get progress_table is unpickled progress table.
def progressTable(p rogress_table, action, task, pid=len(progres s_table), outcome=PROGRES S_OUTCOMES[1]):
pid_column_list =progress_table[0]
task_column_lis t=progress_tabl e[1]
outcome_column_ list=progress_t able[2]

# But a task must also come with an outcome!
def newEntry(new_ta sk, new_outcome):
new_pid=len(tas k_column_list)

pid_column_list .extend(new_pid )
task_column_lis t.extend(new_ta sk)
outcome_column_ list.extend(new _outcome)

def removeEntry(pid _to_remove, task_to_remove) :

if pid_column_list .index(pid_to_r emove)==task_co lumn_list.index (task_to_remove ):
# Must remove all columns for that task
index_for_remov al=pid_column_l ist.index(pid_t o_remove)

pid_column_list .remove(index_f or_removal)
task_column_lis t.remove(index_ for_removal)
outcome_column_ list.remove(ind ex_for_removal)

# Default action is to modify to pass
def modifyEntry(pid _to_modify, outcome_to_modi fy=PROGRESS_OUT COMES[0]):
index_for_modif ying=pid_column _list.index(pid _to_modify)

# Modify the outcome
outcome_column_ list[index_for_modif ying]=outcome_to_mod ify
--
http://mail.python.org/mailman/listinfo/python-list


--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
it says that progress_table is not defined. i don't know why.
Dec 21 '06 #4
At Wednesday 20/12/2006 19:16, Pyenos wrote:
>could someone tell me what things are wrong with my code?
My crystal ball is at the repair shop - could you please tell us:
- what do you expect the code to do?
- what do you get instead?
- any compiler error messages you see?
- in case of an exception, full traceback as printed by the interpreter?
- Python version in use?
--
Gabriel Genellina
Softlab SRL


_______________ _______________ _______________ _____
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Dec 21 '06 #5

Pyenos wrote:
"Calvin Spealman" <ir********@gma il.comwrites:
On 21 Dec 2006 09:16:58 +1100, Pyenos <py****@pyenos. orgwrote:
import cPickle, shelve
>
could someone tell me what things are wrong with my code?
>
class progress:
>
PROGRESS_TABLE_ ACTIONS=["new","remove", "modify"]
DEFAULT_PROGRES S_DATA_FILE="pr ogress_data"
PROGRESS_OUTCOM ES=["pass", "fail"]
>
>
def unpickleProgres sTable(pickled_ progress_data_f ile):
>
return unpickled_progr ess_table
>
def pickleProgressT able(progress_t able_to_pickle) :
>
return pickled_progres s_data_file
>
# Of course, you get progress_table is unpickled progress table.
def progressTable(p rogress_table, action, task, pid=len(progres s_table), outcome=PROGRES S_OUTCOMES[1]):
pid_column_list =progress_table[0]
task_column_lis t=progress_tabl e[1]
outcome_column_ list=progress_t able[2]
>
# But a task must also come with an outcome!
def newEntry(new_ta sk, new_outcome):
new_pid=len(tas k_column_list)
>
pid_column_list .extend(new_pid )
task_column_lis t.extend(new_ta sk)
outcome_column_ list.extend(new _outcome)
>
def removeEntry(pid _to_remove, task_to_remove) :
>
if pid_column_list .index(pid_to_r emove)==task_co lumn_list.index (task_to_remove ):
# Must remove all columns for that task
index_for_remov al=pid_column_l ist.index(pid_t o_remove)
>
pid_column_list .remove(index_f or_removal)
task_column_lis t.remove(index_ for_removal)
outcome_column_ list.remove(ind ex_for_removal)
>
# Default action is to modify to pass
def modifyEntry(pid _to_modify, outcome_to_modi fy=PROGRESS_OUT COMES[0]):
index_for_modif ying=pid_column _list.index(pid _to_modify)
>
# Modify the outcome
outcome_column_ list[index_for_modif ying]=outcome_to_mod ify
It is hard to determine what is wrong with your code without you
telling anyone why it is you believe something is wrong with it. Did
you get an exception? Did it simply not do what it was expected to do?
There seems to be some apparent indenting problems, but maybe that is
just from pushing it through the e-mail. I see some general stylistic
problems as well, but without know what you are actually asking, I
won't know what questions to answer. "What is wrong with my code?" is
a container of many many smaller questions, and you need to focus your
questions better.

it says that progress_table is not defined. i don't know why.
It looks like you have bigger problems than an undefined variable.
Python does not have implicit access to methods and attributes
(members) like C++ and Java do. Methods must accept an explicit self
parameter that refers to the object (analogous to this in C++ and Java)
to access attributes. Your code defines a class, but self is nowhere
to be found.

I suggest getting a good book and/or reading the tutorial
(http://docs.python.org/tut/) and making sure you can do easy stuff
first.
Carl Banks

Dec 21 '06 #6
thanks for your point. so because i have said class blah: i must
explicitly say self for every instantiation of object?
Dec 21 '06 #7
Pyenos wrote:
thanks for your point. so because i have said class blah: i must
explicitly say self for every instantiation of object?

http://docs.python.org/tut/
Carl Banks

Dec 21 '06 #8
Pyenos <py****@pyenos. orgwrote in
news:87******** ****@pyenos.pye nos.org:
thanks for your point. so because i have said class blah: i must
explicitly say self for every instantiation of object?
No, for every method within the class.

Given:

class Blah(object):
def method1(self,ar g1):
self.x = arg1
b = Blah() # b is an instance of class Blah

b.method1(32) # when you invoke it, just pass arg1

print b.x # prints 32

The use of 'self' is just a convention, but a *very* common one,
and one you should follow if you expect other Python programmers
to read your code. This is legal, and has the same effect as the
above class:

class Blah2(object):
def method1(spugsl, arg1):
spugsl.x = arg1

Spugsl (or self) is just the way to refer to the instance within
the code.

In your code, each method wound up with a different name, and none
of the names would have been associated with what you would have
expected. So for example, in

def removeEntry(pid _to_remove, task_to_remove) :

.... your equivalent to 'self' would be pid_to_remove, and the pid
you passed in would have been associated with task_to_remove.

--
rzed

Dec 21 '06 #9
Hi,

this is the line that breaks your code:

def progressTable(p rogress_table, action, task, pid=len(progres s_table)

your parameter progress_table is known inside the function, not inside its definition. So "pid=len(progre ss_table)" won't do.

If you really think that it is possible that pid is anything else but "len(progress_t able)", you should use for example -1 as the default value and calculate the length inside your functions if the parameter is not different. Otherwise dump this parameter.

Hope that helps!

Greetings

Nils
-------- Original-Nachricht --------
Datum: 21 Dec 2006 09:16:58 +1100
Von: Pyenos <py****@pyenos. org>
An: py*********@pyt hon.org
Betreff: what is wrong with my code?
import cPickle, shelve

could someone tell me what things are wrong with my code?

class progress:

PROGRESS_TABLE_ ACTIONS=["new","remove", "modify"]
DEFAULT_PROGRES S_DATA_FILE="pr ogress_data"
PROGRESS_OUTCOM ES=["pass", "fail"]
def unpickleProgres sTable(pickled_ progress_data_f ile):

return unpickled_progr ess_table

def pickleProgressT able(progress_t able_to_pickle) :

return pickled_progres s_data_file

# Of course, you get progress_table is unpickled progress table.
def progressTable(p rogress_table, action, task,
pid=len(progres s_table), outcome=PROGRES S_OUTCOMES[1]):
pid_column_list =progress_table[0]
task_column_lis t=progress_tabl e[1]
outcome_column_ list=progress_t able[2]

# But a task must also come with an outcome!
def newEntry(new_ta sk, new_outcome):
new_pid=len(tas k_column_list)

pid_column_list .extend(new_pid )
task_column_lis t.extend(new_ta sk)
outcome_column_ list.extend(new _outcome)

def removeEntry(pid _to_remove, task_to_remove) :

if
pid_column_list .index(pid_to_r emove)==task_co lumn_list.index (task_to_remove ):
# Must remove all columns for that task
index_for_remov al=pid_column_l ist.index(pid_t o_remove)

pid_column_list .remove(index_f or_removal)
task_column_lis t.remove(index_ for_removal)
outcome_column_ list.remove(ind ex_for_removal)

# Default action is to modify to pass
def modifyEntry(pid _to_modify,
outcome_to_modi fy=PROGRESS_OUT COMES[0]):
index_for_modif ying=pid_column _list.index(pid _to_modify)

# Modify the outcome
outcome_column_ list[index_for_modif ying]=outcome_to_mod ify
--
http://mail.python.org/mailman/listinfo/python-list
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
Dec 21 '06 #10

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

Similar topics

125
14909
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
72
5913
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for example, between a C/C++ programmers with a few weeks of experience and a C/C++ programmer with years of experience. You don't really need to understand the subtle details or use the obscure features of either language
121
10228
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
51
13399
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this wrong????? Function x select case z
56
4367
by: Cherrish Vaidiyan | last post by:
Frinds, Hope everyone is doing fine.i feel pointers to be the most toughest part in C. i have just completed learning pointers & arrays related portions. I need to attend technical interview on C. wat type of questions should be expected? Which part of C language do the staff give more concern? The interviewers have just mentioned that .. i will have interview on C. Also can anyone can help me with sites where i can go thru sample
46
4285
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do believe MSFT should do to improve C#, however. I know that in the "Whidbey" release of VS.NET currently
13
5069
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
98
4641
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
20
2830
by: Daniel.C | last post by:
Hello. I just copied this code from my book with no modification : #include <stdio.h> /* count characters in input; 1st version */ main() { long nc; nc = 0;
0
9864
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
10926
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
10666
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
9445
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7846
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
7024
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4081
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3140
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.