New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys.cmd_flags patch #46141
Comments
The output should be self explaining: I'll provide doc updates and a mini test if the patch wanted. |
I like the idea of exposing Python's command line flags, but I think It also looks like the patch includes a few unrelated changes to |
The new patch is using a struct sequence (like the result of os.stat): >>> import sys
>>> sys.flags
<sys.flags (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)>
>>> dir(sys.flags)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__ge__', '__getattribute__', '__getitem__', '__getslice__',
'__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__',
'__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__rmul__', '__setattr__', '__str__', 'debug',
'division_new', 'division_warning', 'dont_write_bytecode',
'ingnore_environment', 'inspect', 'interactive', 'n_fields',
'n_sequence_fields', 'n_unnamed_fields', 'no_site', 'optimize',
'py3k_warning', 'tabcheck', 'unicode', 'verbose']
>>> sys.flags.debug
0 Please ignore the other files. They are part of my second PEP. |
Can't you use a namedtuple? Then printing it would show the names of |
Guido van Rossum wrote:
... and increase the startup costs of Python by loading several |
Agreed. It's kind of unfortunate that we have two implementations for |
On Jan 13, 2008 9:45 AM, Christian Heimes <report@bugs.python.org> wrote:
Can we make it a function so that it is lazy? That way you can still |
I've coded sys.flags for my per-user site-packages PEP. I could make it |
Does anybody see a problem with this repr slot implementation for >>> os.stat(".")
<posix.stat_result st_mode=16832, st_ino=11666571L, st_dev=65025L,
st_nlink=20, st_uid=1000, st_gid=1000, st_size=4096L,
st_atime=1200261754, st_mtime=1200261721, st_ctime=1200261721> static PyObject *
structseq_repr(PyStructSequence *obj)
{
PyObject *tup, *val, *repr;
PyTypeObject *typ = Py_TYPE(obj);
int i, len;
char buf[250+5]; /* "...>\0" */
char *cname, *crepr;
char *pbuf = buf;
char *endbuf = &buf[250];
if ((tup = make_tuple(obj)) == NULL) {
return NULL;
}
for (i=0; i < VISIBLE_SIZE(obj); i++) {
cname = typ->tp_members[i].name;
val = PyTuple_GetItem(tup, i);
if (cname == NULL || val == NULL) {
return NULL;
}
repr = PyObject_Repr(val);
if (repr == NULL) {
Py_DECREF(tup);
return NULL;
}
crepr = PyString_AsString(repr);
if (crepr == NULL) {
Py_DECREF(tup);
Py_DECREF(repr);
return NULL;
}
len = strlen(cname) + strlen(crepr) + 3;
if ((pbuf+len) < endbuf) {
strcpy(pbuf, cname);
pbuf += strlen(cname);
*pbuf++ = '=';
strcpy(pbuf, crepr);
pbuf += strlen(crepr);
*pbuf++ = ',';
*pbuf++ = ' ';
Py_DECREF(repr);
}
else {
strcpy(pbuf, "...");
pbuf += 5;
Py_DECREF(repr);
break;
}
}
Py_DECREF(tup);
repr = PyString_FromString(buf);
return repr;
} |
Nice -- perhaps you can make it look like a function call, |
Committed in r59947, r59948 and r59949 |
I’ve recently remarked that -i maps to both sys.flags.inspect and sys.flags.interactive. Is this behavior useful? |
Maybe not, but note that there is both a Py_InteractiveFlag and Py_InspectFlag, and they enable different things (they are both set by -i, while setting the PYTHONINSPECT envvar only activates Py_InspectFlag). |
Okay, so having both flags makes sense. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: