stat() got an unexpected keyword argument 'follow_symlinks' - python

Web search found links to bugs, I don't write complicated code on Python, just want to confirm I understand syntax:
https://docs.python.org/3/library/pathlib.html
Path.stat(*, follow_symlinks=True)ΒΆ
But when I write Path(filepath).stat(follow_symlinks=False) I'm getting "stat() got an unexpected keyword argument 'follow_symlinks'" error. lstat() in place of stat(follow_symlinks=False) does job done.
Python 3.8.5. TIA

You're reading it correctly. You just missed the footnote. From the page you linked
Changed in version 3.10: The follow_symlinks parameter was added.
So if you want to use that keyword argument, you need Python 3.10 or newer. Otherwise, as you've already figured out, just use lstat.

Related

Python - got an unexpected keyword argument 'scope'

I am trying to run the 1.0-lunarlander-sim.ipynb file from the Deep Assist GitHub repo. But I keep getting an error: got an unexpected keyword argument 'scope'.
raw_full_pilot_policy, full_pilot_reward_data = deepq.learn(
env,
q_func=full_pilot_q_func,
max_timesteps=max_timesteps,
scope=full_pilot_scope,
**pilot_dqn_learn_kwargs
)
(without knowing deepq), by looking in it's code you can see that scope is not a valid keyword argument for the learn function.
see here:
https://github.com/openai/baselines/blob/master/baselines/deepq/deepq.py#L95
seems that it was removed in that commit, maybe install that version of openai/baselines
https://github.com/openai/baselines/blob/8c2aea2addc9f3ba36d4a0c937e6a2d09830afc7/baselines/deepq/deepq.py

Format of responses to help() in Python shell

I have a question about how certain "help()" items show up in my Python 3.6.2 IDLE shell running on Windows. From the docs, I'd expect to see sum(iterable[, start]) and pow (x, y[, z]), but calling help on those yields sum(iterable, start=0, /) , and pow(x, y, z=None, /). There may be other functions that display the same way.
I'm curious about why they put the descriptor in keyword form (which you cannot use explicitly when calling the functions, as doing so throws a "x takes no keyword arguments" error), but mostly, what is the slash doing there?
[Adding a bit to the linked answer...]
In Python3, documentation of optional args in signatures was changed from brackets, as in '[, start]' (with the default hopefully given in the docstring) to directly giving the default, as in 'start=0'. Sometime later (perhaps 3.4), '/' was (gradually) added to the signature of C-coded functions that do not allow passing an argument by keyword. Before this, there was no easy way to discover the fact without trial and exception. (I believe that there are a few optional args that do not have a default. These have to continue with brackets.)
None of this has anything to do with IDLE, which prints help() output as received. That is why I removed the tag. However, IDLE for current 3.6 and 3.7 adds the following to tooltips when the signature contains '/'.
['/' marks preceding arguments as positional-only]
I don't know if help() should do the same.

Python 2.6: encode() takes no keyword arguments

Hopefully simple question here, I have a value that based on if its unicode, must be encoded. I use the built in string.encode class
code is simple:
if value_t is unicode:
values += (value.encode('utf-8', errors='backslashreplace'), None)
continue
However it returns "encode() takes no keyword arguments"
I am running this in python 2.6, I couldn't find any documentation saying this didn't exist in 2.6
Is there a way for me to make sure it isn't being overwritten by an encode function in a different library? or some sort of solution to it.
It seems like you are able to use string.encode in 2.6 (https://docs.python.org/2.6/howto/unicode.html) so I am not really sure why it wouldn't be working. I am working on one file in a fairly big system, so I am worried this is somehow being overwritten. Either that or some module I need isn't installed..But i am lost
The Python docs for encode explain why you're seeing this issue. Specifically: Changed in version 2.7: Support for keyword arguments added
Since method signatures tend to change from version to version, You should always read the relevant documentation to version you are working with
From str.encode documentation for python 2.6, the method signature is:
str.encode([encoding[, errors]])
There is no errors keyword argument, but the second parameter can be used for the same purpose.

Python-LDAP Size limit exceeded

I see there is a way for me page the results in python and I found the following example code:
https://bitbucket.org/jaraco/python-ldap/src/f208b6338a28/Demo/paged_search_ext_s.py
When I copy this code and try to modify it to what I need it to do when running the code I get a "TypeError: init() got an unexpected keyword argument 'cookie'"
I even reverted the code back to its default and get the same error. If someone could point me in the correct direction it would be much appreciated.
Thanks
Update your python-ldap module:
pip install python-ldap --upgrade
That class changed from this commit and mentioned:
new class API in ldap.controls, not backwards-compatible!
The problem is on this line:
req_ctrl = SimplePagedResultsControl(True,size=self.page_size,cookie='')
Find where that SimplePagedResultsControl class is defined and examine the parameter list for its constructor to get the correct constructor parameter list.
EDIT:
Looks like the constructor signature has been changed. Either upgrade as Omid Raha recommends or try the old method signature below if you are unable to upgrade for some reason.
paged_results_control = SimplePagedResultsControl(ldap.LDAP_CONTROL_PAGE_OID, True, (self.page_size, ''))

Cannot set pdr_use_farkas option in Z3py

When I try to set the fixedpoint engine to PDR, and I try to set the pdr_use_farkas option, I am getting an unknown_parameter error.
In particular, I am using the following options on the fixedpoint object:
fp.set(engine='1',pdr_use_farkas=True,unbound_compressor=False,compile_with_widening=True)
This causes the error:
z3.types.Z3Exception: "unknown parameter ':pdr-use-farkas'"
Using set_option doesn't help either. I tried
set_option(dl_engine='1')
set_option(dl_pdr_use_farkas=True)
and I'm getting "unknown option".
Where am I making the mistake?
I'm using Z3 4.3.1 64bit.
The parameter names have changed between versions as newer versions include a name-space mechanism for parameter names. The Python API has a method for listing parameter descriptions: For example:
fp = Fixedpoint()
print fp.param_descrs()
prints the set of available parameters (permalink: rise4fun.com/Z3Py/r32)

Categories