以下代码在python 2机器上成功运行:
base64_str = base64.encodestring('%s:%s' % (username,password)).replace('\n', '')
Run Code Online (Sandbox Code Playgroud)
我试图将它移植到Python 3,但是当我这样做时,我遇到以下错误:
>>> a = base64.encodestring('{0}:{1}'.format(username,password)).replace('\n','')
Traceback (most recent call last):
File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 519, in _input_type_check
m = memoryview(s)
TypeError: memoryview: str object does not have the buffer interface
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 548, in encodestring
return encodebytes(s)
File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 536, in encodebytes
_input_type_check(s)
File "/auto/pysw/cel55/python/3.4.1/lib/python3.4/base64.py", line 522, in …Run Code Online (Sandbox Code Playgroud) 我有一个关于Linux深入工作的问题.
假设在CPU中正在执行多线程进程.在这种情况下,我们将有一个在CPU上执行的线程.在更广泛的图片中,我们将属于Process的相应页面加载到RAM中以供执行.
让我们说线程进行系统调用.我对此之后的运作有点不清楚.中断将生成一个呼叫.我的一个问题是谁将接听这个电话?
让我们说系统有m:n用户级线程到内核级线程映射,我假设相应的内核级线程将回答此调用.
因此,内核将查找中断向量表并获取需要执行的例程.我的下一个问题是在执行中断时将使用哪个堆栈?它是内核线程的堆栈还是用户级别的线程堆栈?(我假设它将是内核线程的堆栈.)
回到程序流程可以说操作是使用打开文件fopen.我接下来的问题是如何从ISR跳转到系统调用?或者我们的ISR是否映射到系统调用?
当内核线程正在执行时,我还假设RAM上的"OS区域"将用于容纳正在执行系统调用的页面.
再次从不同的角度看待它(希望你还在我身边)最后我假设相应的内核线程正在由CPU调度程序处理,在这里,从用户级线程到相应的内核级线程的上下文切换当fopen系统调用被回答时.
我已经做了很多假设,如果有人能够清除疑虑或者至少引导我朝着正确的方向前进,那绝对是太棒了.
我正在尝试导入另一个文件夹中存在的包,它在python 3.4中运行得非常好.例如:文件存在于libraries文件夹中
user> python
Python 3.4.1 (default, Nov 12 2014, 13:34:29)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from libraries.controller_utils import *
>>>
Run Code Online (Sandbox Code Playgroud)
但是,当我打开一个新的shell并使用Python 2.7时:
user> python
Python 2.7.4 (default, Jun 1 2015, 10:35:58)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from libraries.controller_utils import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No …Run Code Online (Sandbox Code Playgroud) 我是python的新手,我试图理解如何将Python与C/C++联系起来.考虑问题:检查给定的链接列表是否是回文.从这个来源,我发现了一个非常有效的解决方案:
// Initial parameters to this function are &head and head
bool isPalindromeUtil(struct node **left, struct node *right)
{
/* stop recursion when right becomes NULL */
if (right == NULL)
return true;
/* If sub-list is not palindrome then no need to
check for current left and right, return false */
bool isp = isPalindromeUtil(left, right->next);
if (isp == false)
return false;
/* Check values at current left and right */
bool isp1 = (right->data == (*left)->data); …Run Code Online (Sandbox Code Playgroud) python ×3
python-2.7 ×2
python-3.4 ×2
base64 ×1
c ×1
encoding ×1
linux ×1
linux-kernel ×1
pointers ×1
python-3.x ×1
system-calls ×1