我正在读取csv文件中的数据,其中有日期元素,但日期不一致.
例如:有时日期元素就像1/1/2011,有时它就像01/01/2011
由于我以后正在绘制这些数据...这会在我的情节中引起很大的噪音.以下是我的日期课程.你能帮我解决在哪里以及如何修改代码以获取表单中的日期01/01/2011
import re
class Date:
def __init__(self, input_date):
self._input_date = input_date
self._date = None
self._month = None
self._year = None
self._hour = None
self._min = None
def setDate(self):
date = self._input_date
#date = re.findall('w+',date)
date = self.__mySplit()
#print"len ",len(date)
assert (len(date) >= 3) #has atleast dd/mm/yy
#dateLength = len(date[0])
self._month = int(date[0])
self._date = int(date[1])
self._year = int(date[2])
if (len(date) ==5):
self._hour = int(date[3])
self._min = int(date[4])
def __mySplit(self): #splitting the date by delimiters.. …Run Code Online (Sandbox Code Playgroud) 出于某种原因,在Python 2.7的形式表达tuple > list的回报True,但tuple < list和tuple == list回报False.这是为什么?
无论如何,这种观察对我来说并不是原创.
假设我有一些课程B和一些A我无法控制的课程:
class B
class A { def getB: B = ... }
Run Code Online (Sandbox Code Playgroud)
有时结果getB是有效的B,有时是null.我有一个可选项A,我希望得到一个可选项B.这是我可以弄清楚如何做到的"最简单"方式:
val a: Option[A] = ...
val b: Option[B] = a flatMap {x => Option(x.getB)}
Run Code Online (Sandbox Code Playgroud)
我想摆脱名字x,所以我尝试了这个,这并不简单:
val b: Option[B] = a map {_.getB} flatMap Option.apply
Run Code Online (Sandbox Code Playgroud)
我试着作曲_.getB用Option,和我工作的唯一的另一件事是不太简单:
val b: Option[B] = a flatMap {((x: A) => x.getB) andThen Option.apply _}
Run Code Online (Sandbox Code Playgroud)
什么是更简单的方法?这似乎是一个普遍的问题,有一个优雅的解决方案.我真正想要的是接近这一点,这显然是不可能的:
val b: Option[B] = a flatMap …Run Code Online (Sandbox Code Playgroud) 我的代码面临着一个非常奇怪的问题,我无法将元素推入列表中.
我正在尝试实现扫描填充算法.我想要在屏幕上绘制的点列表,以便我可以检查扫描线是否与它们相交.在我的Screen :: plot_pixel函数中,我将Point推入mapped_points列表.但是当我遍历列表时,它是空的.(我正在使用友元函数迭代shape.cpp)
我尝试使用套装但无济于事.我已经附加了控制台输出我也得到了.
plot_pixel被多次调用,我通过在那里添加一个print语句验证了这一点但是这些点拒绝被推入.这是我的所有代码,point.h
#ifndef POINT_H
#define POINT_H
class Point
{
float x_coordinate,y_coordinate;
public:
Point(){}
Point(float x, float y):x_coordinate(x),y_coordinate(y){}
float get_x() const{return x_coordinate;}
float get_y() const {return y_coordinate;}
bool operator==(const Point rhs)const
{
if( ((int)x_coordinate == (int)rhs.get_x()) && ((int)y_coordinate == (int)rhs.get_y()) )
return true;
else return false;
}
bool operator<(const Point rhs)const
{
if((int)x_coordinate < (int)rhs.get_x())
return true;
else return false;
}
};
#endif
Run Code Online (Sandbox Code Playgroud)
screen.h
#ifndef SCREEN_H
#define SCREEN_H
#include<graphics.h>
#include "point.h"
#include<list>
class Shape;
class Screen
{ …Run Code Online (Sandbox Code Playgroud)