我正在用Python编写一个Windows命令行目录导航器,并在os.path.join中苦苦挣扎.从本质上讲,这就是我要做的事情:
abspath = "C:\Python32\Projects\ls.py"
abspath = abspath.split('\\')
print(abspath) #this prints ['C:', 'Python32', 'Projects', 'ls.py']
if(options.mFlag):
print(os.path.join(*abspath)) #this prints C:Python32\Projects\ls.py
m = time.ctime(os.path.getmtime(os.path.join(*abspath))) #this throws an exception
Run Code Online (Sandbox Code Playgroud)
问题是os.path.join没有在'C:'之后插入'/',我无法弄清楚原因.有帮助吗?
编辑:如果将来有人来这里寻找解决方案,我只是在"C:"之后添加了os.sep,而不是硬编码反斜杠,这很有用.
我有一个扩展SherlockActivity的类,因为我在活动中使用了ActionBarSherlock操作栏.但是,我还尝试向此活动中的列表视图添加上下文菜单,该列表视图在列表视图中的项目被长按时启动.我在声明中遇到错误onContextItemSelected(MenuItem item),说我的覆盖无效,因为没有什么可以覆盖.但是,当我删除覆盖时,永远不会调用该函数.我知道这与SherlockActivity从Activity继承的方式有关,但我不确定具体细节.也许我错过了一个导入?请在此处查看相关代码:
public class Inbox extends SherlockActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inbox);
refreshMsgs(this.getCurrentFocus());
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
if (v.getId() == R.id.lstInbox){
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
String contactName = lstConversation.get(info.position).getContactName();
menu.setHeaderTitle(contactName);
menu.add(Menu.NONE, 0, 0, "View contact");
menu.add(Menu.NONE, 1, 1, "Delete thread");
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
SmsConversation selectedConvo = lstConversation.get(info.position);
if (item.getItemId() == 0){
//view contact …Run Code Online (Sandbox Code Playgroud) 我在EditText中显示格式化文本,如下所示:
String msg = <b>Some text here</b>;
EditText txtMsg = (EditText) findViewById(R.id.txtMessage);
txtMsg.setText(Html.fromHtml(msg));
Run Code Online (Sandbox Code Playgroud)
它在EditText中显示为" 这里有一些文字. "然后,我想从EditText中拉出带有标签的文本.但是,当我使用时:
txtMsg.getText().toString();
Run Code Online (Sandbox Code Playgroud)
它只是给了我"这里的一些文字"没有格式.
有什么想法吗?
相关代码:
msg = "Subject: Reset password instructions\n\nHello " + @request_payload["email"] + "!\n\n" +
"A new account has been created for you at <a href=\"presentation-layer.dev\">presentation-layer.dev<a>." +
"Please go to that page and click \"forgot password\" to set your password."
smtp = Net::SMTP.new 'smtp.gmail.com', 587
smtp.enable_starttls
smtp.start('domain', "email", 'password', :login) do
smtp.send_message(msg, 'sender', "recip")
end
Run Code Online (Sandbox Code Playgroud)
生成的电子邮件中只包含原始文本.如何让服务器评估HTML标记?
我有两个CharFields,我需要这样做,以便用户需要填写其中一个但不是两个(独占或).是否有捷径可寻?码:
def __init__(self, *args, **kwargs):
super(AddMemberByUsernameForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
'username',
'student_id',
'title',
'tags',
FormActions(
Submit('save', _('Save changes'))
)
)
username = forms.CharField() #field1
student_id = forms.CharField() #field2 - these are the two fields
title = forms.CharField()
tags = forms.MultipleChoiceField(
required=False,
widget=forms.CheckboxSelectMultiple,
choices=[(x.id, x.name) for x in membership_ops.get_all_membership_tags()]
)
Run Code Online (Sandbox Code Playgroud)