如何使用python在twitter上使用hashtags?(How to use the hashtags on twitter using python?)
谁能告诉我如何在Python中使用Twitter的检索主题标签? 我试过用过:
test = api.GetUserTimeline() for i in test: text = i.text hashtag = i.hashtags print text print "\n" + hashtag
它将
hashtag
返回为None
,而在文本中它是“life is #wonderful”Can anyone tell me how to use retrieve hashtags from Twitter in Python? I have tried using:
test = api.GetUserTimeline() for i in test: text = i.text hashtag = i.hashtags print text print "\n" + hashtag
It returns
hashtag
asNone
, while in the text it is "life is #wonderful"
原文:https://stackoverflow.com/questions/7034880
最满意答案
只有在Spring Context中只存在一个特定类型的实现bean时,自动装配才有效。 我假设使用泛型D扩展BaseDao导致Spring试图自动装配BaseDao实例而不是UserDao和ApprovalDao的情况。 因为UserDao和ApprovalDao都实现了BaseDao,所以Spring上下文包含BaseDao的多个实现,无法决定应该使用哪个。
Spring试图在堆栈跟踪中告诉你
org.springframework.beans.factory.NoSuchBeanDefinitionException: __No unique bean of type__ [com.primetech.core.parent.BaseDAO] is defined: expected single matching bean but found 2: [userDAO, approvalDAO]
您可以尝试使用实际dao类型在具体服务中定义dao来测试这一点,例如
public abstract class BaseService<K, E extends BaseEntity, D extends BaseDAO<K, E>> { private final D dao; protected BaseService(D dao) { this.dao = dao; } } public class UserService extends BaseService<K, User, UserDao<K, User>> { @Autowired public UserService(UserDao dao) { super(dao); } }
我将继续为UserDao和ApprovalDao定义接口,以便依赖关系在接口而不是实现上。 daos可能仍然具有共同的超级接口,并且它们的实现可以基于BaseDao以避免不必要的重复。
在示例中,我在构造函数中定义了注入的Dao,因为我假设在服务的整个生命周期中应该使用相同的dao实例,并且如果没有dao set,服务就不能存在。 在我看来,构造函数参数更好地传达了这个契约。 此外,它可能使该类更易于测试和维护。
Autowiring works only if there is exactly one implementation bean of the specific type present in the Spring Context. I'd assume that using the generic D extends BaseDao leads to a situation where Spring is trying to autowire instances of BaseDao instead of UserDao and ApprovalDao. Because you both UserDao and ApprovalDao implement BaseDao, Spring context contains multiple implementations of BaseDao and cannot decide which one should be used.
Spring is trying to tell this to you in the stack trace
org.springframework.beans.factory.NoSuchBeanDefinitionException: __No unique bean of type__ [com.primetech.core.parent.BaseDAO] is defined: expected single matching bean but found 2: [userDAO, approvalDAO]
You could try to test this by defining the dao in the concrete service using the actual dao type e.g.
public abstract class BaseService<K, E extends BaseEntity, D extends BaseDAO<K, E>> { private final D dao; protected BaseService(D dao) { this.dao = dao; } } public class UserService extends BaseService<K, User, UserDao<K, User>> { @Autowired public UserService(UserDao dao) { super(dao); } }
I'd continue by defining interfaces for UserDao and ApprovalDao so that dependencies are on interfaces and not implementations. The daos may still have a common super interface and their implementations may be based on the BaseDao to avoid unnecessary duplication.
In the example I've defined the injected Dao in the constructor because I assume that the same dao instance should be used throughout the lifetime of the service and the service cannot exist without the dao set. In my opinion, a constructor argument communicates this contract better. Furthermore it might make the class a bit more testable and maintainable.
相关问答
更多-
你想要: void DoAllFoo() { using expand = int[]; static_cast
(expand{ 0, (static_cast (this)->Foo(), void(), 0)... }); } 要么: void DoAllFoo() { using expand = int[]; static_cast (expand{ 0, (Bases::Foo(), void(), 0)... }); } 取 ... -
不,如果您没有在类定义中明确定义超类,那么您正在创建一个根类 。 来自可可核心能力 : 一个根类不继承其他类,并定义一个接口和行为对它下面的层次结构中的所有对象都是通用的。 该层次结构中的所有对象最终都会从根类继承。 根类有时被称为基类。 所有Objective-C类的根类都是NSObject ,它是Foundation框架的一部分。 Cocoa或Cocoa Touch应用程序中的所有对象最终都从NSObject继承。 这个类是其他类与Objective-C运行时交互的主要接入点。 它还声明基本的对象接口并 ...
-
在Unity中使用GetComponent时,通过基类管理派生类?(Manage derived classes via a base class when using GetComponent in Unity?)[2022-04-20]
您没有正确设置基类的menuType 。 而不是在派生类的Awake方法中设置它,在构造函数中设置它,如下所示: public class UI_Toggleable { public UIMenus MenuType {get;} // Subclasses must pass the correct menuType here protected UI_Toggleable(UIMenus menuType) { MenuType = menuType; ... -
将派生类的方法重构为公共基类的方法?(Refactoring Derived Classes' Methods to Common Base Class' Method? (C#))[2022-11-14]
更好的方法是在func调用的基类中定义virtual (或abstract )方法。 然后在每个子类中,您可以使用特定指令覆盖该方法, func将使用子类的行为。 public class MyBase { protected virtual void DoCommand() { throw new NotImplementedException(); } public void Func() { ... DoCommand(); . ... -
继承,我如何让两个类共享相同的基类内容?(Inheritance , how can i make two classes share the same base class contents?)[2023-09-01]
一个最小的完整示例看起来像这样: #includeusing namespace std; class VAR { public: int var; virtual ~VAR() {} void setVar(int n) {var=n;} }; class Out :public VAR {}; class FSM :public VAR {}; int main() { FSM x; x.setVar(5); Out OP; i ... -
只有在Spring Context中只存在一个特定类型的实现bean时,自动装配才有效。 我假设使用泛型D扩展BaseDao导致Spring试图自动装配BaseDao实例而不是UserDao和ApprovalDao的情况。 因为UserDao和ApprovalDao都实现了BaseDao,所以Spring上下文包含BaseDao的多个实现,无法决定应该使用哪个。 Spring试图在堆栈跟踪中告诉你 org.springframework.beans.factory.NoSuchBeanDefinitionE ...
-
C#:基类中的静态成员(C# : Static Members in Base Class)[2023-11-07]
接口定义了一个接口。 只要你有任何“真实”的东西,不管是方法实现还是共享数据,你都需要一个类,在这种情况下需要一个抽象类。 另一种方法是保持接口,但添加单例以保存与实现接口的类相关的数据。 如果您需要使用界面,那么我认为这是一条路。 只需命名单身人士,它显然它在逻辑上与界面链接,并且文档,界面的实现应该使用它。 在你的情况下,静态类与数据可能是足够的,而不是完整的单例实现,但我不会在这里进入这里,整个“静态类与单身”是有点争议的主题。 Interface defines just that, an inte ... -
以下是3个选项:1-根据数据动态选择适配器类型,2-将数据从一种类型转换为另一种类型3-实现读取多种数据类型的适配器。 选项1,动态选择适配器。 - 听起来像最简单的解决方案,除非有什么阻止你这样做 - 比如必须同时显示来自2个来源的数据。 选项2,转换数据。 - 也很好的解决方案。 将光标读入列表或映射imo很容易,然后只需实现一个读取映射数据的适配器。 @Luksprog还提供了一个选项2解决方案 - 它将为simpleCursorAdapter提供一个包含其他数据的MatrixCursor。 但不管怎 ...
-
公共基类初始化(Common base class initialization)[2022-02-23]
您在寻找以下功能吗? //dummy class replacing the service object and it's methods public class MyServiceObject { public void ServiceMethod1(SubSubC param) { } public void ServiceMethod2(SubSubE param) { } } public ... -
实际上,您输入的示例其实是有效的,但不允许进行许多有用的更改。 联合体非活动成员的任何部分唯一有效的左值到右值转换是访问该成员与活动成员([class.mem] / 23)的公共初始序列的一部分。 但是,常见的初始序列仅为两个标准布局结构([class.mem] / 20)定义,并且有很多规则可以作为标准布局结构([class] / 7)。 总结: 该类可能不是多态的。 该类可能不会有多个具有相同类型的基类。 该类可能没有引用类型的非静态成员。 该类的所有非静态成员都具有相同的访问控制。 所有非静态成员(包 ...