我正在尝试编写一个python程序,最终将获取文件的命令行参数,确定它是否是tar或zip等文件,然后相应地对其进行exctract.我只是试图让tar部分工作,我得到了多个错误.我正在检查的文件位于我的〜/目录中.任何想法都会很棒.
#!/usr/bin/python
import tarfile
import os
def open_tar(file):
if tarfile.is_tarfile(file):
try:
tar = tarfile.open("file")
tar.extractall()
tar.close()
except ReadError:
print "File is somehow invalid or can not be handled by tarfile"
except CompressionError:
print "Compression method is not supported or data cannot be decoded"
except StreamError:
print "Is raised for the limitations that are typical for stream-like TarFile objects."
except ExtractError:
print "Is raised for non-fatal errors when using TarFile.extract(), but only if TarFile.errorlevel== 2."
if __name__ == '__main__':
file = …Run Code Online (Sandbox Code Playgroud) 问候-
我有2节课.一个称为"程序",另一个称为"日志".名为Programs的类public const string m_sEnviron = "";接近顶部,我需要通过名为Logs的类来检查m_sEnviron变量的设置.变量m_sEnviron将从名为Tidal的调度程序中设置,因此如何从其他类检查其值.如果这不是最好的,请告诉我更好的方法.
提前致谢.
问候,
Namespace NightScripts
{
class Program
{
public static string m_sEnviron {get; set;}
static void Main(string[] args)
{
}
//Lots of other functions...
}
class Logs
{
//I try to get access to m_sEnviron but it will not show after I type Program.
}
}
Run Code Online (Sandbox Code Playgroud) 我有这个.htaccess规则:
RewriteRule viewshoplatest/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/$ /viewshoplatest.php?$1=$2&$3=$4&$5=$6&$7=$8&$9=$10&$11=$12&$13=$14&$15=$16
Run Code Online (Sandbox Code Playgroud)
它应该映射这样的URL:
http://www.veepiz.com/viewshoplatest/start/10/end/10/filter/0/ownerid/0/sortby/date/sortdir/DESC/cat/0/scat/0/
Run Code Online (Sandbox Code Playgroud)
对此:
http://www.veepiz.com/viewshoplatest.php?start=0&end=10&filter=0&ownerid=0&sortby=date&sortdir=DESC&cat=0&scat=0
Run Code Online (Sandbox Code Playgroud)
当我点击链接并打印$_GET变量时,我得到了这个:
Array ( [start] => 10 [end] => 10 [filter] => 0 [ownerid] => 0 [sortby] => start0 [start1] => start2 [start3] => start4 [start5] => start6 )
Run Code Online (Sandbox Code Playgroud)
关于它为什么表现不好的任何想法?
好吧,我通过重写规则来解决这个问题
RewriteRule viewshoplatest/start/(.*)/end/(.*)/filter/(.*)/ownerid/(.*)/sortby/(.*)/sortdir/(.*)/cat/(.*)/scat/(.*)/$ /viewshoplatest.php?start=$1&end=$2&filter=$3&ownerid=$4&sortby=$5&sortdir=$6&cat=$7&scat=$8
Run Code Online (Sandbox Code Playgroud) 我正在使用MySQL 5.5的最新EclipseLink版本(表类型InnoDB).我一次插入大约30900条记录(也可能更多).问题是,插入性能非常差:插入所有记录大约需要22秒(与JDBC相比:7秒).我读过使用批量写作应该有帮助 - 但不是!?
@Entity
public class TestRecord {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
public int test;
}
Run Code Online (Sandbox Code Playgroud)
插入记录的代码:
factory = Persistence.createEntityManagerFactory("xx_test");
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
for(int i = 0; i < 30900; i++) {
TestRecord record = new TestRecord();
record.test = 21;
em.persist(record);
}
em.getTransaction().commit();
em.close();
Run Code Online (Sandbox Code Playgroud)
最后我的EclipseLink配置:
<persistence-unit name="xx_test" transaction-type="RESOURCE_LOCAL">
<class>com.test.TestRecord</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/xx_test" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="test" />
<property name="eclipselink.jdbc.batch-writing" value="JDBC" />
<property name="eclipselink.jdbc.cache-statements" value="true"/>
<property …Run Code Online (Sandbox Code Playgroud) 我有两个MapKit注释,显示纬度和经度.
有什么方法可以通过现有的Objective-C iOS API函数来计算两者之间的距离吗?
我在磁盘上有一个SQL CE 4.0数据库,以及一个我想用来填充该数据库的LINQPad程序.
我正在使用内置的(到LINQPad)linq2sql系统.我注意到随着时间的推移,插入一批行所花费的时间会花费越来越多的时间,最终看起来程序已经慢慢爬行了.
是否有某种缓存或类似缓慢的缓存?如果有的话,我可以做些什么来避免这种减速?
这是我用来测试它的简单测试表:
CREATE TABLE dummy
(
id int not null primary key identity (1, 1),
value nvarchar(20) not null
)
Run Code Online (Sandbox Code Playgroud)
和我的测试程序:
void Main()
{
for (int iteration = 1; iteration <= 1000; iteration++)
{
Stopwatch sw = Stopwatch.StartNew();
for (int row = 0; row < 100; row++)
dummy.InsertOnSubmit(new dummy { value = "row#" + row });
var create = sw.ElapsedMilliseconds;
SubmitChanges();
sw.Stop();
var total = sw.ElapsedMilliseconds;
Debug.WriteLine("iteration " + iteration + ", create=" + …Run Code Online (Sandbox Code Playgroud) 我正在研究计算机体系结构。在逻辑运算部分,它提出了这个问题:
哪些操作可以隔离单词中的字段?
我不确定这些规定的操作如何在一个单词中隔离一个字段。我尝试搜索示例,但找不到任何示例。有人能为此提供更深入的解释和例子吗?谢谢。
刚才我在我的 Powershell 脚本中观察到一些奇怪的东西,我终于把它缩小到我的代码中的一个错误,就是这一行:
$AnyExecuted = true
Run Code Online (Sandbox Code Playgroud)
应该是
$AnyExecuted = $true
Run Code Online (Sandbox Code Playgroud)
但是,这一行会在 Windows 10 上的标准 Powershell Core 窗口以及 Windows 终端中搞乱转义码处理:
有谁知道为什么会这样?true表达方式是什么?我找不到任何提及它,为什么它会对 Powershell 的输出产生这种影响?
请注意,显然我更新了我的脚本以使用 $true,这是我的意图,这个问题只是关于什么true是。
我有以下代码:
using System;
using System.Linq;
using System.Linq.Expressions;
public class Program
{
public static void Main()
{
Descendant d = new Descendant();
d.TestMethod();
}
}
public class Base
{
protected void FigureItOut<TClass, TMember>(Expression<Func<TClass, TMember>> expr)
{
}
}
public class Descendant : Base
{
public void TestMethod()
{
FigureItOut(c => c.Name);
}
public String Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我收到此编译器错误消息:
The type arguments for method
'Base.FigureItOut<TClass,TMember>
(System.Linq.Expressions.Expression<System.Func<TClass,TMember>>)'
cannot be inferred from the usage. Try specifying the type arguments explicitly.
Run Code Online (Sandbox Code Playgroud)
如果我将对ImageItOut的调用更改为: …
是的,我是c#的新手!:)我正在使用.Net4 VS2010.
我有三个类,每个类用于构建该类型的对象列表.这三个都继承了基类.
我想将结果三个列表合并为一个,并在其中一个基类元素上对它们进行排序.
这可以用不同类型的列表完成吗?
简化示例:
每个列表都已创建
public List<TestOne> TestOne list;
public List<TestTwo> TestTwoList;
public List<object> BothLists;
Run Code Online (Sandbox Code Playgroud)
填写TestOne和TestTwo的代码......
什么/如何将TestOne和TestTwo结合到BothLists中并在SeqNumber上对它们进行排序?
public class BaseClassTest
{
public string Loc { get; set; } // loc
// sequence number to order by will be assigned in the resulting class
public int SeqNumber { get; set; }
}
public class TestOne : BaseClassTest
{
public int Number { get; set; }
}
public class TestTwo : BaseClassTest
{
public string CatName { get; set; } …Run Code Online (Sandbox Code Playgroud) c# ×4
.net ×1
apache ×1
architecture ×1
cocoa-touch ×1
eclipselink ×1
ios ×1
linqpad ×1
list ×1
mapkit ×1
mkmapview ×1
mod-rewrite ×1
objective-c ×1
powershell ×1
python ×1