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

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_PROGRESS_DATA_FILE="progress_data"
PROGRESS_OUTCOMES=["pass", "fail"]
def unpickleProgressTable(pickled_progress_data_file):

return unpickled_progress_table

def pickleProgressTable(progress_table_to_pickle):

return pickled_progress_data_file

# Of course, you get progress_table is unpickled progress table.
def progressTable(progress_table, action, task, pid=len(progress_table), outcome=PROGRESS_OUTCOMES[1]):
pid_column_list=progress_table[0]
task_column_list=progress_table[1]
outcome_column_list=progress_table[2]

# But a task must also come with an outcome!
def newEntry(new_task, new_outcome):
new_pid=len(task_column_list)

pid_column_list.extend(new_pid)
task_column_list.extend(new_task)
outcome_column_list.extend(new_outcome)

def removeEntry(pid_to_remove, task_to_remove):

if pid_column_list.index(pid_to_remove)==task_column_ list.index(task_to_remove):
# Must remove all columns for that task
index_for_removal=pid_column_list.index(pid_to_rem ove)

pid_column_list.remove(index_for_removal)
task_column_list.remove(index_for_removal)
outcome_column_list.remove(index_for_removal)

# Default action is to modify to pass
def modifyEntry(pid_to_modify, outcome_to_modify=PROGRESS_OUTCOMES[0]):
index_for_modifying=pid_column_list.index(pid_to_m odify)

# Modify the outcome
outcome_column_list[index_for_modifying]=outcome_to_modify
Dec 20 '06 #1
9 2101
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_PROGRESS_DATA_FILE="progress_data"
PROGRESS_OUTCOMES=["pass", "fail"]
def unpickleProgressTable(pickled_progress_data_file):

return unpickled_progress_table

def pickleProgressTable(progress_table_to_pickle):

return pickled_progress_data_file

# Of course, you get progress_table is unpickled progress table.
def progressTable(progress_table, action, task, pid=len(progress_table), outcome=PROGRESS_OUTCOMES[1]):
pid_column_list=progress_table[0]
task_column_list=progress_table[1]
outcome_column_list=progress_table[2]

# But a task must also come with an outcome!
def newEntry(new_task, new_outcome):
new_pid=len(task_column_list)

pid_column_list.extend(new_pid)
task_column_list.extend(new_task)
outcome_column_list.extend(new_outcome)

def removeEntry(pid_to_remove, task_to_remove):

if pid_column_list.index(pid_to_remove)==task_column_ list.index(task_to_remove):
# Must remove all columns for that task
index_for_removal=pid_column_list.index(pid_to_rem ove)

pid_column_list.remove(index_for_removal)
task_column_list.remove(index_for_removal)
outcome_column_list.remove(index_for_removal)

# Default action is to modify to pass
def modifyEntry(pid_to_modify, outcome_to_modify=PROGRESS_OUTCOMES[0]):
index_for_modifying=pid_column_list.index(pid_to_m odify)

# Modify the outcome
outcome_column_list[index_for_modifying]=outcome_to_modify
--
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********@gmail.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_PROGRESS_DATA_FILE="progress_data"
PROGRESS_OUTCOMES=["pass", "fail"]
def unpickleProgressTable(pickled_progress_data_file):

return unpickled_progress_table

def pickleProgressTable(progress_table_to_pickle):

return pickled_progress_data_file

# Of course, you get progress_table is unpickled progress table.
def progressTable(progress_table, action, task, pid=len(progress_table), outcome=PROGRESS_OUTCOMES[1]):
pid_column_list=progress_table[0]
task_column_list=progress_table[1]
outcome_column_list=progress_table[2]

# But a task must also come with an outcome!
def newEntry(new_task, new_outcome):
new_pid=len(task_column_list)

pid_column_list.extend(new_pid)
task_column_list.extend(new_task)
outcome_column_list.extend(new_outcome)

def removeEntry(pid_to_remove, task_to_remove):

if pid_column_list.index(pid_to_remove)==task_column_ list.index(task_to_remove):
# Must remove all columns for that task
index_for_removal=pid_column_list.index(pid_to_rem ove)

pid_column_list.remove(index_for_removal)
task_column_list.remove(index_for_removal)
outcome_column_list.remove(index_for_removal)

# Default action is to modify to pass
def modifyEntry(pid_to_modify, outcome_to_modify=PROGRESS_OUTCOMES[0]):
index_for_modifying=pid_column_list.index(pid_to_m odify)

# Modify the outcome
outcome_column_list[index_for_modifying]=outcome_to_modify
--
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********@gmail.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_PROGRESS_DATA_FILE="progress_data"
PROGRESS_OUTCOMES=["pass", "fail"]
>
>
def unpickleProgressTable(pickled_progress_data_file):
>
return unpickled_progress_table
>
def pickleProgressTable(progress_table_to_pickle):
>
return pickled_progress_data_file
>
# Of course, you get progress_table is unpickled progress table.
def progressTable(progress_table, action, task, pid=len(progress_table), outcome=PROGRESS_OUTCOMES[1]):
pid_column_list=progress_table[0]
task_column_list=progress_table[1]
outcome_column_list=progress_table[2]
>
# But a task must also come with an outcome!
def newEntry(new_task, new_outcome):
new_pid=len(task_column_list)
>
pid_column_list.extend(new_pid)
task_column_list.extend(new_task)
outcome_column_list.extend(new_outcome)
>
def removeEntry(pid_to_remove, task_to_remove):
>
if pid_column_list.index(pid_to_remove)==task_column_ list.index(task_to_remove):
# Must remove all columns for that task
index_for_removal=pid_column_list.index(pid_to_rem ove)
>
pid_column_list.remove(index_for_removal)
task_column_list.remove(index_for_removal)
outcome_column_list.remove(index_for_removal)
>
# Default action is to modify to pass
def modifyEntry(pid_to_modify, outcome_to_modify=PROGRESS_OUTCOMES[0]):
index_for_modifying=pid_column_list.index(pid_to_m odify)
>
# Modify the outcome
outcome_column_list[index_for_modifying]=outcome_to_modify
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.pyenos.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,arg1):
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(progress_table, action, task, pid=len(progress_table)

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

If you really think that it is possible that pid is anything else but "len(progress_table)", 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*********@python.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_PROGRESS_DATA_FILE="progress_data"
PROGRESS_OUTCOMES=["pass", "fail"]
def unpickleProgressTable(pickled_progress_data_file):

return unpickled_progress_table

def pickleProgressTable(progress_table_to_pickle):

return pickled_progress_data_file

# Of course, you get progress_table is unpickled progress table.
def progressTable(progress_table, action, task,
pid=len(progress_table), outcome=PROGRESS_OUTCOMES[1]):
pid_column_list=progress_table[0]
task_column_list=progress_table[1]
outcome_column_list=progress_table[2]

# But a task must also come with an outcome!
def newEntry(new_task, new_outcome):
new_pid=len(task_column_list)

pid_column_list.extend(new_pid)
task_column_list.extend(new_task)
outcome_column_list.extend(new_outcome)

def removeEntry(pid_to_remove, task_to_remove):

if
pid_column_list.index(pid_to_remove)==task_column_ list.index(task_to_remove):
# Must remove all columns for that task
index_for_removal=pid_column_list.index(pid_to_rem ove)

pid_column_list.remove(index_for_removal)
task_column_list.remove(index_for_removal)
outcome_column_list.remove(index_for_removal)

# Default action is to modify to pass
def modifyEntry(pid_to_modify,
outcome_to_modify=PROGRESS_OUTCOMES[0]):
index_for_modifying=pid_column_list.index(pid_to_m odify)

# Modify the outcome
outcome_column_list[index_for_modifying]=outcome_to_modify
--
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
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...
72
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...
121
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...
51
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...
56
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...
46
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...
13
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
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
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...
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...

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.