小编que*_*sis的帖子

字符串的Python调用函数

s = "func"
Run Code Online (Sandbox Code Playgroud)

现在假设有一个称为func的函数。当函数名以字符串形式给出时,如何在Python 2.7中调用func?

python python-2.7

1
推荐指数
1
解决办法
7383
查看次数

Python语法错误没有被捕获

from __future__ import print_function

try:
    print "a"
except SyntaxError:
    print('error')
Run Code Online (Sandbox Code Playgroud)

为什么SyntaxError异常没有被抓住?我使用的是Python 2.7

输出:

  File "test", line 4
    print "a"
            ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

python exception-handling python-2.7

1
推荐指数
1
解决办法
183
查看次数

Python 十六进制字符串检查是否设置了位

给定一个由十六进制数组成的字符串。

s = "F716F92C8Aba"
Run Code Online (Sandbox Code Playgroud)

确定n从右计数的第 th 位是否设置为 1的最简单方法是什么?所以n=0将是最正确的一点。

蟒蛇 2.7

python python-2.7

0
推荐指数
1
解决办法
1081
查看次数

获取对列表Python

c = [1,2,3,4,5,6,7,8,9,10]

for a,b in func(c):
    doSomething()
Run Code Online (Sandbox Code Playgroud)

所以func()必须返回 (1,2) (2,3) (3,4) ... (8,9) (9,10)

在python 2.7中是否有一个优雅的方法来实现这一目标?

python list python-2.7

-3
推荐指数
2
解决办法
1414
查看次数

std :: set Unique Pointer

struct departure_compare {
    bool operator() (const Leg* lhs, const Leg* rhs) const
    {
        return lhs->CurrentDepartureTime() < rhs->CurrentDepartureTime();
    }
};

class Station
{
    uint station_number_;
    std::set<Leg *, departure_compare> departure_legs_in_order_; // legs that depart from this station in order of departure time
public:
    Station(uint station_number) : station_number_(station_number) {};
    void addDepartureLeg(Leg *leg) { departure_legs_in_order_.insert(leg); };
    const std::set<Leg *, departure_compare>& DepartureLegs() const { return departure_legs_in_order_; };
    uint StationNumber() { return station_number_; };
};
Run Code Online (Sandbox Code Playgroud)

我把它称为循环

Leg *new_leg = new Leg();
start_station->addDepartureLeg(new_leg); // start_station of type …
Run Code Online (Sandbox Code Playgroud)

c++ pointers std

-3
推荐指数
1
解决办法
174
查看次数

标签 统计

python ×4

python-2.7 ×4

c++ ×1

exception-handling ×1

list ×1

pointers ×1

std ×1