namespaces

How do I create a Python namespace (argparse.parse_args value)?

How do I create a Python namespace (argparse.parse_args value)? Question: To interactively test my python script, I would like to create a Namespace object, similar to what would be returned by argparse.parse_args(). The obvious way, >>> import argparse >>> parser = argparse.ArgumentParser() >>> parser.parse_args() Namespace() >>> parser.parse_args(“-a”) usage: [-h] : error: unrecognized arguments: – a …

Total answers: 4

socket.error:[errno 99] cannot assign requested address and namespace in python

socket.error:[errno 99] cannot assign requested address and namespace in python Question: My server software says errno99: cannot assign requested address while using an ip address other than 127.0.0.1 for binding. But if the IP address is 127.0.0.1 it works. Is it related to namespaces? I am executing my server and client codes in another python …

Total answers: 6

Remove namespace and prefix from xml in python using lxml

Remove namespace and prefix from xml in python using lxml Question: I have an xml file I need to open and make some changes to, one of those changes is to remove the namespace and prefix and then save to another file. Here is the xml: <?xml version=’1.0′ encoding=’UTF-8′?> <package > <provider>some data</provider> <language>en-GB</language> </package> …

Total answers: 10

Visibility of global variables in imported modules

Visibility of global variables in imported modules Question: I’ve run into a bit of a wall importing modules in a Python script. I’ll do my best to describe the error, why I run into it, and why I’m tying this particular approach to solve my problem (which I will describe in a second): Let’s suppose …

Total answers: 9

Iterate through a Namespace

Iterate through a Namespace Question: I have got a namespace looking like this : Namespace(aTQ=None, bE=None, bEQ=None, b=None, bQ=None, c=None, c=None, cJ=None, d=None, g=None, jR=[‘xx’, ‘015’], lC=None, l=None) How can I iterate through it so I can find and replace the ‘xx’ value for the “jR” key in place ? Asked By: Finger twist || …

Total answers: 1

Python: possible to call static method from within class without qualifying the name

Python: possible to call static method from within class without qualifying the name Question: This is annoying: class MyClass: @staticmethod def foo(): print “hi” @staticmethod def bar(): MyClass.foo() Is there a way to make this work without naming MyClass in the call? i.e. so I can just say foo() on the last line? Asked By: …

Total answers: 4

type object 'datetime.datetime' has no attribute 'datetime'

type object 'datetime.datetime' has no attribute 'datetime' Question: I have gotten the following error: type object ‘datetime.datetime’ has no attribute ‘datetime’ On the following line: date = datetime.datetime(int(year), int(month), 1) Does anybody know the reason for the error? I imported datetime with from datetime import datetime if that helps Thanks Asked By: Chris Frank || …

Total answers: 13

Insert variable into global namespace from within a function?

Insert variable into global namespace from within a function? Question: Is it possible to add an object to the global namespace, for example, by using globals() or dir()? def insert_into_global_namespace(var_name, value): globals()[var_name] = value insert_into_global_namespace(‘my_obj’, ‘an object’) print(f’my_obj = {my_obj}’) But this only works in the current module. Asked By: Dan || Source Answers: Yes, …

Total answers: 5