首页 \ 问答 \ Python命令行输入?(Python Command Line input? [duplicate])

Python命令行输入?(Python Command Line input? [duplicate])

可能重复:
你如何从python中读取stdin

什么是从命令行获取信息的最佳/最简单的方法。

例如,我将运行一堆shell脚本,它们返回:

200 SOLUTIONS_REVISION 
or 
400 SOLUTIONS_REVISION

在我运行每个脚本之后。 我需要在python中捕获这些“返回”的字符串作为字符串(以检查它是否通过(200)或失败(400)。这是最好的方法(我是一个完整的新的python和我的搜索似乎主要是返回命令行争论。

谢谢(最好也是python 2.x)


Possible Duplicate:
How do you read from stdin in python

Whats the best/easiest way to get information from a command line.

For example Im going to be running a bunch of shell scripts that return either:

200 SOLUTIONS_REVISION 
or 
400 SOLUTIONS_REVISION

after I run each script. I need to capture these "returned" strings in python as a string (to check if it passes (200) or fails (400). What would be the best way to do this (im a complete newb to python and my search seemed to mainly return getting command line arguements.

Thanks (also python 2.x preferably)


原文:https://stackoverflow.com/questions/6045109
更新时间:2023-04-25 09:04

最满意答案

我不认为你可以使用简单的排名功能来做到这一点。 按时间排序并不能通过lat / lon为您提供所需的组ID,而按地理位置排序则没有多大意义。 什么工作是创建一个标志,说明lat / lon是否已更改并使用此运行总和作为序列/组ID。 然后,您可以按此分组以获得结果。

with cte as
(
  SELECT
    ID, ResourceID, Region, [GPS Time], Latitude, Longitude, 
    lag(LATITUDE, 1) over(order by [gps time]) as prev_LATITUDE,
    lag(LONGITUDE, 1) over(order by [gps time]) as prev_LONGITUDE
  FROM 
    [dbo].[GeofenceReport]
)
, cte2 as
(
  select
    ID, ResourceID, Region, [GPS Time], Latitude, Longitude, 
    SUM(
      -- 1 if location changed, 0 otherwise
      CASE WHEN 
        Latitude <> prev_Latitude 
        OR Longitude <> prev_Longitude THEN 1
      ELSE 0 END
    ) OVER(ORDER BY [GPS Time]) as seq -- running sum over time
  from cte
)
select 
  min(id) as id, min(region) as region, min([GPS Time]) as [GPS Time],
  min(Latitude) as Latitude, min(Longitude) as Longitude
from cte2
group by seq

你更新的SQL小提琴


I don't think you can do this using a simple ranking function. Ordering by time doesn't give you the desired group id by lat/lon and ordering by geo location doesn't make much sense. What would work is to create a flag saying if lat/lon changed and using running sum of this as the sequence/group id. Then you can group by that to get your results.

with cte as
(
  SELECT
    ID, ResourceID, Region, [GPS Time], Latitude, Longitude, 
    lag(LATITUDE, 1) over(order by [gps time]) as prev_LATITUDE,
    lag(LONGITUDE, 1) over(order by [gps time]) as prev_LONGITUDE
  FROM 
    [dbo].[GeofenceReport]
)
, cte2 as
(
  select
    ID, ResourceID, Region, [GPS Time], Latitude, Longitude, 
    SUM(
      -- 1 if location changed, 0 otherwise
      CASE WHEN 
        Latitude <> prev_Latitude 
        OR Longitude <> prev_Longitude THEN 1
      ELSE 0 END
    ) OVER(ORDER BY [GPS Time]) as seq -- running sum over time
  from cte
)
select 
  min(id) as id, min(region) as region, min([GPS Time]) as [GPS Time],
  min(Latitude) as Latitude, min(Longitude) as Longitude
from cte2
group by seq

Your updated SQL fiddle

相关问答

更多
  • 您可以使用简单的子查询来完成此操作 CREATE TABLE Table1 ([organizationID] int, [Code] int, [transactionID] int, [FGName] varchar(13), [itemName] varchar(19)); INSERT INTO Table1 ([organizationID], [Code], [transactionID], [FGName], [itemName]) VALUES (1000 ...
  • 您混淆了主键和聚集索引。 两者没有理由相同。 您可以在FILE_UPLOADED_DATE上拥有聚簇索引,并在FILE_UPLOADED_DATE拥有单独的非群集主键。 事实上,你已经为DocGUID列做了类似的事情: CREATE TABLE [dbo].[FILE]( [FILE_ID] [int] IDENTITY(1,1) NOT NULL, [DOCUMENT] [varbinary](max) FILESTREAM NULL, [FILE_UPLOADED_DATE] ...
  • 以下是我理解您的请求的方法:您首先需要CORRELATION_ID Z,因为其最高的SEQ (9)高于A的最高SEQ (6),但在每个CORRELATION_ID您希望按日期排序记录。 select seq, correlation_id, cr_timestamp from mytable order by max(seq) over (partition by correlation_id) desc, cr_timestamp desc; Here is how I understand your ...
  • 我觉得你很亲密。 基本上,您只需要降序排序即可获得最新版本: SELECT rc.* FROM (SELECT rc.*, RANK() OVER (PARTITION BY ID, RC_CLASS ORDER BY rc_date DESC) AS LATEST_VERSION FROM table rc ) rc WHERE LATEST_VERSION = 1 ORDER BY rc_vendorid; 我注意到你使用RANK() 。 如果您在同一日 ...
  • 如果要在视图中添加行号,是否只需要没有分区的order by ? 如果是这样,您可以使用以下之一,具体取决于数据库: select row_number() over () select row_number() over (order by NULL) select row_number() over (order by (select NULL)) 您的方法是枚举相同的行,而不是在所有行上提供行号。 If you want to add a row number to the view, don't ...
  • 您的查询非常接近。 而不是做max ,做一个row_number() : select target_name,value,collection_timestamp from (select target_name,value,collection_timestamp, row_number() over (partition by target_name order by value desc) as seqnum from mgmt$metric_details ...
  • 我不认为你可以使用简单的排名功能来做到这一点。 按时间排序并不能通过lat / lon为您提供所需的组ID,而按地理位置排序则没有多大意义。 什么工作是创建一个标志,说明lat / lon是否已更改并使用此运行总和作为序列/组ID。 然后,您可以按此分组以获得结果。 with cte as ( SELECT ID, ResourceID, Region, [GPS Time], Latitude, Longitude, lag(LATITUDE, 1) over(order by [g ...
  • 我创建了自己的表并编写了自己的查询。 使用EXPLAIN PARTITIONS我发现使用此方法在日期上进行分区实际上使用了分区修剪。 I created my own tables and wrote my own queries. Using EXPLAIN PARTITIONS I found that partitioning on dates using this method does actually employ partition pruning.
  • 您是否考虑在查询中使用QUALIFY子句? SELECT cust_grp_id , fc_id FROM table1 QUALIFY ROW_NUMBER() OVER (PARTITION BY cust_grp_id ORDER BY eff_to_dt desc) = 1; Have you considered using the QUALIFY clause in your query? SEL ...
  • 如果最大技能数未知,则需要使用动态sql。 您需要使用row_number()对PersonId分区的每个列表进行编号,以便与pivot() 。 测试设置: create table t (skillid int, personid int, skill varchar(32)); insert into t values (1,1,'sql-server'),(3,1,'sql'),(9,2,'sql-server'); declare @cols nvarchar(max); declare @sql ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)