473,493 Members | 4,334 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

need hint for refactoring

I have a bunch of function like:

def p2neufrage(_):
""" create new element"""
anfrage,ergebnis=getanfrage()
if ergebnis.get("status","ok") == "ok":
wert=anfrage["feld"]
# do something
# unique here
ergebnis["innerHTML"]=..... something ....

#
return simplejson.dumps(ergebnis, skipkeys=False,
ensure_ascii=False, check_circular=True, allow_nan=True)
so, everywhere there is the same beginning:

anfrage,ergebnis=getanfrage()

I analyze some transmitted jason-document; check for errors

then I take the values out of the request, process it and fill the
slots of a result ("ergebnis") dictionary, which is returned.
So the beginning and the end of the function is allways repeated. It
would be great to factor it out ... i startet with that ...getanfrage()
call.

Is there anything more possible?

Thanks for any hint

Harald

Aug 9 '06 #1
1 1336
GHUM wrote:
I have a bunch of function like:

def p2neufrage(_):
""" create new element"""
anfrage,ergebnis=getanfrage()
if ergebnis.get("status","ok") == "ok":
wert=anfrage["feld"]
# do something
# unique here
ergebnis["innerHTML"]=..... something ....

#
return simplejson.dumps(ergebnis, skipkeys=False,
ensure_ascii=False, check_circular=True, allow_nan=True)
so, everywhere there is the same beginning:

anfrage,ergebnis=getanfrage()

I analyze some transmitted jason-document; check for errors

then I take the values out of the request, process it and fill the
slots of a result ("ergebnis") dictionary, which is returned.
So the beginning and the end of the function is allways repeated. It
would be great to factor it out ... i startet with that ...getanfrage()
call.

Is there anything more possible?
Use a decorator, out of my head:

def foo(f):
def _w(*args, **kwargs):
anfrage,ergebnis=getanfrage()
new_args = (args[0],) + (anfrage, ergebnis) + args[1:]
f(*new_args, **kwargs)
return simplejson.dumps(ergebnis, skipkeys=False,
ensure_ascii=False, check_circular=True, allow_nan=True)

return _w

Then do

@foo
def p2neufrage(_, anfrage, ergebnis):
""" create new element"""
if ergebnis.get("status","ok") == "ok":
wert=anfrage["feld"]
# do something
# unique here
ergebnis["innerHTML"]=..... something ....
Diez
Aug 9 '06 #2

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

Similar topics

1
2215
by: Guenther Schmidt | last post by:
Hi, does anyone know a good PHP IDE with refactoring capabilities? Refactoring meaning things like moving methods around from a subclass into the superclass, renaming methods and local...
9
2015
by: Peter Dembinski | last post by:
I am trying to write Master Thesis on refactoring Python code. Where should I look for information? -- http://www.dembiński.prv.pl
4
1581
by: | last post by:
Hi, Refactoring a winform causes problems if moving this form to a subdirectory in the same project. What is the workaround for this and will this be fixed in future? Thanks /BOB
4
1538
by: Jack Wright | last post by:
Dear All, I have found some sites on "refactoring" but I would like to know if MS will be integrating some kind of "refactoring" functionality in VS for .Net 2.0? Or do I still have to depend on...
8
3874
by: Juan | last post by:
Hi, Does anyone if is there any refactoring browser (or some ide supporting refactoring) for C++ ? There are two dead projects in sourceforge, but I found nothing more... Regards, - Juancho
2
2085
by: Sachin Garg | last post by:
Hi, I was trying to find (like many others here) a tool for refactoring C++ code as I have lately been noticing that I spend most of my coding time doing refactoring and some refactoring which...
3
1415
by: Arne Styve | last post by:
Hi, The good old Borland JBuilder has very good support for patterns (GoF) and refactoring. Does such support exsist for VS.NET and C# specifically ? The type of support I'm looking for is to...
8
1995
by: Frank Rizzo | last post by:
I keep hearing this term thrown around. What does it mean in the context of code? Can someone provide a definition and example using concrete code? Thanks.
15
4358
by: Simon Cooke | last post by:
Does anyone know of any tools for refactoring header files? We're using a third party codebase at work, and pretty much every file includes a 50Mb precompiled header file. I'm looking for a tool...
0
6980
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
7157
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,...
1
6862
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...
0
7364
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...
1
4886
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...
0
4579
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...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1397
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 ...

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.