是否有任何可以自動查詢XML文件和/或RDBMS表的Python類似於LINQ的項目?該語法不一定非常像C#中的LINQ,但希望以pythonic的方式關閉。LINQ in Python
回答
如果你正在尋找一個ORM再有就是SQLAlchemy
Pynq實現表達式樹:
http://wiki.github.com/heynemann/pynq
微軟創建使用表達式樹的LINQ(語言集成查詢),這是一種關於如何將操作解析到樹中的數學概念,以便您可以獨立於結果分析操作。
Pynq是表達式樹理論和一些提供者的Python實現。逐漸會有更多的提供商,但Pynq將努力使自己的提供商儘可能地容易編寫。
聲音很酷。 8年未觸及。 – Robino 2017-03-15 11:14:51
你可能想看看kalamar:http://dyko.org/api/kalamar.html
它是利用語法或多或少類似於LINQ訪問存儲在不同格式數據的統一數據訪問庫(XML,MP3,...)上異構後端(文件,sql,...)。
我還沒有使用它,但是這表明承諾:
asq是一個簡單的實施Python中的LINQ風格的API,它工作在Python的iterables,包括在以下方面實現並行版本的Python標準庫多處理模塊。 API體育功能與對象的LINQ等同,100%聲明測試覆蓋率和comprehensive documentation。
2012年在Google Code上打開了一個問題,2015年7月遷移到GH,未於2017年7月解決https://github.com/sixty-north/asq/issues/5 – scls 2017-07-01 21:21:27
@scls rob-smallshire爲您提供了答案並關閉了問題 – 2017-09-07 16:59:38
我覺得Pony ORM應該在這裏提到。對我來說,這是 LINQ:
q = select((p.name, p.price) for p in Product)
q2 = q.filter(lambda n, p: n.name.startswith(「A」) and p > 100)
或直接從他們的着陸頁:
select(c for c in Customer
if sum(c.orders.price) > 1000)
如果您正在尋找跨語言的LINQ,它的發生地點是在Reactive Extensions其中微軟正在實施Python,Ruby,JavaScript等。這需要LINQ,所以他們通常最終會首先執行LINQ運算符;)
- 官方Python版本是在這裏:https://rxpy.codeplex.com/
- 但這裏還有另外一個端口:http://akuendig.github.io/RxPython/
只是爲了好玩我創建了以下代碼。
"""This module provides linq-like extensions for some common data structures"""
import __builtin__
class extlist(list):
"""subclass of list"""
def where(self, condition):
return extlist(filter(condition, self))
def aggregate(self, condition):
return extlist(reduce(condition, self))
def select(self, condition=lambda x: x):
return extlist(map(condition, self))
__builtin__.list = extlist
class extstr(str):
"""subclass of str"""
def where(self, condition):
return extstr(filter(condition, self))
def aggregate(self, condition):
return extstr(reduce(condition, self))
def select(self, condition=lambda x: x):
return extstr(map(condition, self))
__builtin__.str = extstr
使用
a = list('apple')
a.where(lambda u: u == 'p').select(lambda x: x.upper())
[ 'P', 'P']
我們推出PythonQL,這基本上是LINQ的Python類固醇(好吧,也許維生素)。它是Python語法的擴展,但是(drumrolls)你可以通過pip來安裝它,它不會破壞任何現有的代碼:)檢查出來:www.pythonql.org
- 1. LINQ to SQL in and not in
- 2. LINQ-to-SQL IN()
- 3. Foreach in Linq
- 4. Vector3 in Meep in Python
- 5. linq in或包含?
- 6. OrderBy in LINQ to Entity
- 7. LINQ to SQL WHERE「IN」
- 8. Linq SelectMany in Entity Framework
- 9. Signin in Linq to Sql?
- 10. SelectMany in Linq to entity
- 11. LINQ的。載或IN
- 12. Linq查詢中的'IN'和'NOT IN'
- 13. LINQ - SELECT DISTINCT與NOT IN
- 14. LINQ to SQL - How to「Where ... in ...」
- 15. orderby Count(other_table)in linq查詢
- 16. 多對多LINQ「IN」查詢
- 17. LINQ的NOT IN子句?
- 18. LINQ to Objects - NOT IN查詢
- 19. var in linq的使用
- 20. 'Random'Orderby in webservice using LINQ To Entities
- 21. group by select max in linq
- 22. StartsWith string.empty in linq查詢
- 23. in linq中的條款
- 24. 如何使用Linq「NOT IN」
- 25. LINQ風味IS IN查詢
- 26. 「Where In」with linq to sql
- 27. DefaultIfEmpty - LINQ to SQL vs In Memory
- 28. Linq vb.net - 其中X IN(SELECT ...)
- 29. __rlshift__,__ror__ in Python
- 30. Quicksort in place Python
請注意,有[pyquery](http:// pypi .python.org/pypi/pyquery),一個像Python一樣的jquery-syntax /功能包。 – user712092 2011-08-30 16:27:45
py-enumerable/py_linq https://github.com/viralogic/py-enumerable可以幫助 – scls 2017-07-01 21:16:44